Github user vofque commented on a diff in the pull request: https://github.com/apache/spark/pull/22745#discussion_r227387167 --- 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 { --- End diff -- @cloud-fan, what about this approach: to pass functionName, type getter and array getter as parameters of a private constructor + add two objects with specific constructors?
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org