cloud-fan commented on a change in pull request #33810:
URL: https://github.com/apache/spark/pull/33810#discussion_r694787137
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
##########
@@ -174,16 +175,36 @@ 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")
+ }
+
+ 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, Literal(name, StringType)) =>
+ StructField(name.toString, elementType, nullable = true)
+ case _ =>
+ throw new AnalysisException("Schema name of arrays_zip should be
string literal.")
Review comment:
This means bug, I think IllegalStateException is 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]