Github user dongjoon-hyun commented on a diff in the pull request:
https://github.com/apache/spark/pull/13971#discussion_r69031088
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/generators.scala
---
@@ -141,11 +155,47 @@ case class Explode(child: Expression) extends
UnaryExpression with Generator wit
val rows = new Array[InternalRow](inputMap.numElements())
var i = 0
inputMap.foreach(kt, vt, (k, v) => {
- rows(i) = InternalRow(k, v)
+ rows(i) = if (position) InternalRow(i, k, v) else
InternalRow(k, v)
i += 1
})
rows
}
}
}
}
+
+/**
+ * Given an input array produces a sequence of rows for each value in the
array.
+ *
+ * {{{
+ * SELECT explode(array(10,20)) ->
+ * 10
+ * 20
+ * }}}
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(a) - Separates the elements of array a into multiple
rows, or the elements of map a into multiple rows and columns.",
+ extended = "> SELECT _FUNC_(array(10,20));\n 10\n 20")
+// scalastyle:on line.size.limit
+case class Explode(child: Expression)
+ extends ExplodeBase(child, position = false) with Serializable {
+}
+
+/**
+ * Given an input array produces a sequence of rows for each position and
value in the array.
+ *
+ * {{{
+ * SELECT explode(array(10,20)) ->
+ * 0 10
+ * 1 20
+ * }}}
+ */
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = "_FUNC_(a) - Separates the elements of array a into multiple
rows with positions, or the elements of a map into multiple rows and columns
with positions.",
+ 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) with Serializable {
--- End diff --
Actually, this is needed. Without this, there occurs runtime errors. This
happens usually when extending `abstract` base classes.
---
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]