Github user gatorsmile commented on a diff in the pull request: https://github.com/apache/spark/pull/9358#discussion_r46650981 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/Encoder.scala --- @@ -37,3 +35,39 @@ trait Encoder[T] extends Serializable { /** A ClassTag that can be used to construct and Array to contain a collection of `T`. */ def clsTag: ClassTag[T] } + +object Encoder { + import scala.reflect.runtime.universe._ + + def forBoolean: Encoder[java.lang.Boolean] = ExpressionEncoder(flat = true) + def forByte: Encoder[java.lang.Byte] = ExpressionEncoder(flat = true) + def forShort: Encoder[java.lang.Short] = ExpressionEncoder(flat = true) + def forInt: Encoder[java.lang.Integer] = ExpressionEncoder(flat = true) + def forLong: Encoder[java.lang.Long] = ExpressionEncoder(flat = true) + def forFloat: Encoder[java.lang.Float] = ExpressionEncoder(flat = true) + def forDouble: Encoder[java.lang.Double] = ExpressionEncoder(flat = true) + def forString: Encoder[java.lang.String] = ExpressionEncoder(flat = true) + + def typeTagOfTuple2[T1 : TypeTag, T2 : TypeTag]: TypeTag[(T1, T2)] = typeTag[(T1, T2)] + + private def getTypeTag[T](c: Class[T]): TypeTag[T] = { + import scala.reflect.api + + // val mirror = runtimeMirror(c.getClassLoader) + val mirror = rootMirror + val sym = mirror.staticClass(c.getName) + val tpe = sym.selfType + TypeTag(mirror, new api.TypeCreator { + def apply[U <: api.Universe with Singleton](m: api.Mirror[U]) = + if (m eq mirror) tpe.asInstanceOf[U # Type] + else throw new IllegalArgumentException( + s"Type tag defined in $mirror cannot be migrated to other mirrors.") + }) + } + + def forTuple2[T1, T2](c1: Class[T1], c2: Class[T2]): Encoder[(T1, T2)] = { --- End diff -- @marmbrus Any reason why it is tuple 5, instead of tuple 22 which is the current limit of Scala?
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org