Github user vofque commented on a diff in the pull request:
https://github.com/apache/spark/pull/22745#discussion_r227420673
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
@@ -1787,3 +1787,72 @@ case class ValidateExternalType(child: Expression,
expected: DataType)
ev.copy(code = code, isNull = input.isNull)
}
}
+
+object GetKeyArrayFromMap {
+
+ /**
+ * Construct an instance of GetArrayFromMap case class
+ * extracting a key array from a Map expression.
+ *
+ * @param child a Map expression to extract key array from
+ */
+ def apply(child: Expression): Expression = {
+ GetArrayFromMap(
+ child,
+ "keyArray",
+ { case MapType(kt, _, _) => kt },
+ _.keyArray())
+ }
+}
+
+object GetValueArrayFromMap {
+
+ /**
+ * Construct an instance of GetArrayFromMap case class
+ * extracting a value array from a Map expression.
+ *
+ * @param child a Map expression to extract value array from
+ */
+ def apply(child: Expression): Expression = {
+ GetArrayFromMap(
+ child,
+ "valueArray",
+ { case MapType(_, vt, _) => vt },
+ _.valueArray())
+ }
+}
+
+/**
+ * Extracts a key/value array from a Map expression.
+ *
+ * @param child a Map expression to extract array from
+ * @param source source of array elements, can be `Key` or `Value`
+ */
+case class GetArrayFromMap private(
+ child: Expression,
+ functionName: String,
+ elementTypeGetter: MapType => DataType,
+ arrayGetter: MapData => ArrayData) extends UnaryExpression with
NonSQLExpression {
+
+ private lazy val encodedFunctionName: String =
TermName(functionName).encodedName.toString
+
+ lazy val dataType: DataType = {
+ child.dataType match {
+ case mt @ MapType(_, _, _) =>
+ ArrayType(elementTypeGetter(mt))
+ case other =>
--- End diff --
Done
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]