sarutak commented on a change in pull request #33106:
URL: https://github.com/apache/spark/pull/33106#discussion_r659861818
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##########
@@ -181,16 +181,35 @@ case class MapKeys(child: Expression)
""",
group = "array_funcs",
since = "2.4.0")
-case class ArraysZip(children: Seq[Expression]) extends Expression with
ExpectsInputTypes {
+case class ArraysZip(children: Seq[Expression], names: Seq[Expression])
+ extends Expression with ExpectsInputTypes {
+
+ def this(children: Seq[Expression]) = {
+ this(
+ children,
+ children.zipWithIndex.map {
+ case (u: UnresolvedAttribute, _) => Literal(u.nameParts.last)
+ case (e: NamedExpression, _) if e.resolved => Literal(e.name)
+ case (e: NamedExpression, _) => NamePlaceholder
+ case (_, idx) => Literal(idx.toString)
+ })
+ }
+
+ if (children.size != names.size) {
+ throw new IllegalArgumentException(
+ "The numbers of zipped arrays and field names should be the same")
+ }
+
+ final override val nodePatterns: Seq[TreePattern] = Seq(ARRAYS_ZIP)
+ override lazy val resolved: Boolean =
+ childrenResolved && checkInputDataTypes().isSuccess &&
names.forall(_.resolved)
override def inputTypes: Seq[AbstractDataType] =
Seq.fill(children.length)(ArrayType)
@transient override lazy val dataType: DataType = {
- val fields = children.zip(arrayElementTypes).zipWithIndex.map {
- case ((expr: NamedExpression, elementType), _) =>
- StructField(expr.name, elementType, nullable = true)
- case ((_, elementType), idx) =>
- StructField(idx.toString, elementType, nullable = true)
+ val fields = arrayElementTypes.zip(names).map {
+ case (elementType, name) =>
Review comment:
Thanks. Seems better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]