Github user rxin commented on a diff in the pull request: https://github.com/apache/spark/pull/13976#discussion_r69084526 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/generators.scala --- @@ -149,3 +149,42 @@ case class Explode(child: Expression) extends UnaryExpression with Generator wit } } } + +/** + * Explodes an array of structs into a table. + */ +@ExpressionDescription( + usage = "_FUNC_(a) - Explodes an array of structs into a table.") +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, _) => + et.fields.zipWithIndex.foldLeft(new StructType()) { case (schema, (f, i)) => + schema.add(s"col${i + 1}", f.dataType, nullable = f.nullable) + } + } + + override def eval(input: InternalRow): TraversableOnce[InternalRow] = child.dataType match { + case ArrayType(et : StructType, _) => + val inputArray = child.eval(input).asInstanceOf[ArrayData] + if (inputArray == null) { + Nil + } else { + val rows = new Array[InternalRow](inputArray.numElements()) + inputArray.foreach(et, (i, e) => { --- End diff -- we don't need to materialize the array, do we? We can create an iterator to return the results.
--- 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