You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by dongjoon-hyun <gi...@git.apache.org> on 2016/07/01 00:02:42 UTC

[GitHub] spark pull request #13976: [SPARK-16288][SQL] Implement inline table generat...

Github user dongjoon-hyun commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13976#discussion_r69230152
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/generators.scala ---
    @@ -195,3 +195,43 @@ case class Explode(child: Expression) extends ExplodeBase(child, position = fals
       extended = "> SELECT _FUNC_(array(10,20));\n  0\t10\n  1\t20")
     // scalastyle:on line.size.limit
     case class PosExplode(child: Expression) extends ExplodeBase(child, position = true)
    +
    +/**
    + * Explodes an array of structs into a table.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(a) - Explodes an array of structs into a table.",
    +  extended = "> SELECT _FUNC_(array(struct(1, 'a'), struct(2, 'b')));\n [1,a]\n[2,b]")
    +case class Inline(child: Expression) extends UnaryExpression with Generator with CodegenFallback {
    +
    +  override def children: Seq[Expression] = child :: Nil
    +
    +  override def checkInputDataTypes(): TypeCheckResult = child.dataType match {
    +    case ArrayType(et, _) if et.isInstanceOf[StructType] =>
    +      TypeCheckResult.TypeCheckSuccess
    +    case _ =>
    +      TypeCheckResult.TypeCheckFailure(
    +        s"input to function inline should be array of struct type, not ${child.dataType}")
    +  }
    +
    +  override def elementSchema: StructType = child.dataType match {
    +    case ArrayType(et : StructType, _) =>
    +      var schema = new StructType()
    +      for (f <- et.fields.zipWithIndex) {
    +        schema = schema.add(s"col${f._2 + 1}", f._1.dataType, nullable = f._1.nullable)
    +      }
    +      schema
    +  }
    +
    +  override def eval(input: InternalRow): TraversableOnce[InternalRow] = child.dataType match {
    +    case ArrayType(NullType, _) => Nil
    --- End diff --
    
    Actually, I added this to pass the `Seq.empty` testcase.
    https://github.com/apache/spark/pull/13976/files#diff-6715134a4e95980149a7600ecb71674cR80
    
    But, now, I think I added this without deep thought.



---
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