Github user rxin commented on a diff in the pull request:
https://github.com/apache/spark/pull/4585#discussion_r24713046
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/Column.scala ---
@@ -576,6 +578,25 @@ trait Column extends DataFrame {
override def as(alias: Symbol): Column = exprToColumn(Alias(expr,
alias.name)())
/**
+ * (Scala-specific) Explodes the column to zero or more rows by the
provided function.
+ * {{{
+ * val df = Seq(Tuple1("a b c"), Tuple1("d e")).toDataFrame("words")
+ * val col = df("words")
+ * col.explode {words: String => words.split(" ")}
+ * }}}
+ */
+ def explode[A, B : TypeTag](f: A => TraversableOnce[B]): Column = {
+ val dataType = ScalaReflection.schemaFor[B].dataType
+ val attributes = AttributeReference(schema.fields(0).name, dataType)()
:: Nil
+ def rowFunction(row: Row) = {
+ f(row(0).asInstanceOf[A]).map(o =>
Row(ScalaReflection.convertToCatalyst(o, dataType)))
+ }
+ val generator = UserDefinedGenerator(attributes, rowFunction, expr ::
Nil)
+ val plan = Generate(generator, join = true, outer = false, None,
logicalPlan)
+ Column(sqlContext, Project(attributes, plan), attributes(0))
--- End diff --
i think this will break a lot of things because attributes(0) is different
from the expression in project
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]