Skip to content

Instantly share code, notes, and snippets.

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))
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
@emesday
emesday / StringJoinBenchmark.scala
Last active August 28, 2016 02:59
StringJoinBenchmark
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