This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected def typeToTypeTag[T](tpe: Type): TypeTag[T] = { | |
TypeTag(currentMirror, new TypeCreator { | |
override def apply[U <: Universe with Singleton](m: api.Mirror[U]): U#Type = { | |
tpe.asInstanceOf[U#Type] | |
} | |
}) | |
} | |
protected def typeToClassTag[T](tpe: Type): ClassTag[T] = typeTagToClassTag(typeToTypeTag(tpe)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def topByKey(key: String, orderBy: String, n: Int): DataFrame = { | |
val keyIndex = df.schema.fieldIndex(key) | |
val orderByIndex = df.schema.fieldIndex(orderBy) | |
val ord = df.schema.fields(orderByIndex).dataType match { | |
case o: StringType => Ordering.by[Row, String](_.getString(orderByIndex)) | |
case o: IntegerType => Ordering.by[Row, Int](_.getInt(orderByIndex)) | |
case o: LongType => Ordering.by[Row, Long](_.getLong(orderByIndex)) | |
case o: FloatType => Ordering.by[Row, Float](_.getFloat(orderByIndex)) | |
case o: DoubleType => Ordering.by[Row, Double](_.getDouble(orderByIndex)) | |
case _ => throw new IllegalArgumentException |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package w20160827 | |
case class Log(s: String, l: Long, f: String, t: String, p: String) { | |
def usingFixedSize: String = { | |
// 23 = Long.MaxValue.toString.length + ("\t" * 4).length | |
val size = 23 + s.length + f.length + t.length + p.length | |
val sb = new StringBuilder(size, s) | |
sb append "\t"; sb append l | |
sb append "\t"; sb append f |
NewerOlder