yaooqinn commented on a change in pull request #26371: [SPARK-27976][SQL] Add 
built-in Array Functions: array_append
URL: https://github.com/apache/spark/pull/26371#discussion_r341942785
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
 ##########
 @@ -3928,3 +3928,128 @@ case class ArrayExcept(left: Expression, right: 
Expression) extends ArrayBinaryL
 
   override def prettyName: String = "array_except"
 }
+
+@ExpressionDescription(
+  usage = """
+  _FUNC_(array, element) - Returns an array of appending an element to the end 
of an array
+  """,
+  examples = """
+    Examples:
+      > SELECT _FUNC_(array(1, 2, 3), 3);
+       [1,2,3,3]
+      > SELECT _FUNC_(array(1, 2, 3), null);
+       [1,2,3,null]
+      > SELECT _FUNC_(a, e) FROM VALUES (array(1,2), 3), (array(3, 4), null), 
(null, 3) tbl(a, e);
+       NULL
+       [1,2,3]
+       [3,4,null]
+  """,
+  since = "3.0.0")
+case class ArrayAppend(left: Expression, right: Expression) extends 
BinaryExpression {
 
 Review comment:
   Hi @maropu , the key difference is when the array is null and the new 
element is not, array_append will create new array but concat's result will be 
null. please see the following cases.
   ```
   -- !query 18
   select array_append(a, e) from VALUES (array(1,2), 3), (array(3, 4), null), 
(null, 3), (null, null) tbl(a, e)
   -- !query 18 schema
   struct<array_append(a, e):array<int>>
   -- !query 18 output
   NULL
   [1,2,3]
   [3,4,null]
   [3]
   
   -- !query 19
   select concat(a, array(e)) from VALUES (array(1,2), 3), (array(3, 4), null), 
(null, 3), (null, null) tbl(a, e)
   -- !query 19 schema
   struct<concat(a, array(e)):array<int>>
   -- !query 19 output
   NULL
   NULL
   [1,2,3]
   [3,4,null]
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to