zhengruifeng commented on code in PR #38865: URL: https://github.com/apache/spark/pull/38865#discussion_r1039464912
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala: ########## @@ -4600,3 +4600,69 @@ case class ArrayExcept(left: Expression, right: Expression) extends ArrayBinaryL override protected def withNewChildrenInternal( newLeft: Expression, newRight: Expression): ArrayExcept = copy(left = newLeft, right = newRight) } + +/** + * Given an array, and another element append the element at the end of the array. + */ +@ExpressionDescription( + usage = "_FUNC_(expr, expr) - Prepend the element", + examples = """ + Examples: + > SELECT _FUNC_(array('b', 'd', 'c', 'a'), array(1, 2, 3, 4)); + + """, + since = "3.4.0", + group = "collection_funcs") +case class ArrayAppend(left: Expression, right: Expression) + extends BinaryExpression + with ImplicitCastInputTypes { + override def prettyName: String = "array_append" + override def inputTypes: Seq[AbstractDataType] = Seq(ArrayType, AnyDataType) + + override def checkInputDataTypes(): TypeCheckResult = { + (left.dataType, right.dataType) match { + case (ArrayType(e1, _), (e2)) if e1.sameType(e2) => + TypeCheckResult.TypeCheckSuccess + case _ => Review Comment: For this case, I think we can refer to `ArrayUnion`: ``` scala> spark.sql(""" SELECT array_union(a,b) FROM VALUES (ARRAY(1,2,3), ARRAY(8,9), ARRAY('HELLO')) AS tab(a,b,c) """) res7: org.apache.spark.sql.DataFrame = [array_union(a, b): array<int>] scala> spark.sql(""" SELECT array_union(a,c) FROM VALUES (ARRAY(1,2,3), ARRAY(8,9), ARRAY('HELLO')) AS tab(a,b,c) """) org.apache.spark.sql.AnalysisException: [DATATYPE_MISMATCH.BINARY_ARRAY_DIFF_TYPES] Cannot resolve "array_union(a, c)" due to data type mismatch: Input to function `array_union` should have been two "ARRAY" with same element type, but it's ["ARRAY<INT>", "ARRAY<STRING>"].; line 1 pos 8; 'Project [unresolvedalias(array_union(a#13, c#15), None)] +- SubqueryAlias tab +- LocalRelation [a#13, b#14, c#15] ``` I think we should apply same datatype validation as `ArrayUnion` -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org