You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by gatorsmile <gi...@git.apache.org> on 2015/12/04 06:41:28 UTC

[GitHub] spark pull request: [SPARK-11269][SQL] Java API support & test cas...

Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9358#discussion_r46650956
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/encoders/Encoder.scala ---
    @@ -37,3 +37,120 @@ 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 BOOLEAN: Encoder[java.lang.Boolean] = ExpressionEncoder(flat = true)
    +  def BYTE: Encoder[java.lang.Byte] = ExpressionEncoder(flat = true)
    +  def SHORT: Encoder[java.lang.Short] = ExpressionEncoder(flat = true)
    +  def INT: Encoder[java.lang.Integer] = ExpressionEncoder(flat = true)
    +  def LONG: Encoder[java.lang.Long] = ExpressionEncoder(flat = true)
    +  def FLOAT: Encoder[java.lang.Float] = ExpressionEncoder(flat = true)
    +  def DOUBLE: Encoder[java.lang.Double] = ExpressionEncoder(flat = true)
    +  def STRING: Encoder[java.lang.String] = ExpressionEncoder(flat = true)
    +
    +  def tuple[T1, T2](enc1: Encoder[T1], enc2: Encoder[T2]): Encoder[(T1, T2)] = {
    +    tuple(Seq(enc1, enc2).map(_.asInstanceOf[ExpressionEncoder[_]]))
    +      .asInstanceOf[ExpressionEncoder[(T1, T2)]]
    +  }
    +
    +  def tuple[T1, T2, T3](
    +      enc1: Encoder[T1],
    +      enc2: Encoder[T2],
    +      enc3: Encoder[T3]): Encoder[(T1, T2, T3)] = {
    +    tuple(Seq(enc1, enc2, enc3).map(_.asInstanceOf[ExpressionEncoder[_]]))
    +      .asInstanceOf[ExpressionEncoder[(T1, T2, T3)]]
    +  }
    +
    +  def tuple[T1, T2, T3, T4](
    +      enc1: Encoder[T1],
    +      enc2: Encoder[T2],
    +      enc3: Encoder[T3],
    +      enc4: Encoder[T4]): Encoder[(T1, T2, T3, T4)] = {
    +    tuple(Seq(enc1, enc2, enc3, enc4).map(_.asInstanceOf[ExpressionEncoder[_]]))
    +      .asInstanceOf[ExpressionEncoder[(T1, T2, T3, T4)]]
    +  }
    +
    +  def tuple[T1, T2, T3, T4, T5](
    +      enc1: Encoder[T1],
    +      enc2: Encoder[T2],
    +      enc3: Encoder[T3],
    +      enc4: Encoder[T4],
    +      enc5: Encoder[T5]): Encoder[(T1, T2, T3, T4, T5)] = {
    +    tuple(Seq(enc1, enc2, enc3, enc4, enc5).map(_.asInstanceOf[ExpressionEncoder[_]]))
    +      .asInstanceOf[ExpressionEncoder[(T1, T2, T3, T4, T5)]]
    +  }
    +
    +  private def tuple(encoders: Seq[ExpressionEncoder[_]]): ExpressionEncoder[_] = {
    --- End diff --
    
    @cloud-fan , does that mean the limit will be 22? Do you think we should at least add it up to Tuple22, which is the 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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org