beliefer commented on code in PR #38865:
URL: https://github.com/apache/spark/pull/38865#discussion_r1057063197
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -4600,3 +4600,111 @@ 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_(array, element) - Add the element at the end of the array
passed as first
+ argument. Type of element should be similar to type of the elements of
the array.""",
Review Comment:
```suggestion
usage = """
_FUNC_(array, element) - Add the element at the end of the array passed
as first
argument. Type of element should be similar to type of the elements of
the array.
""",
```
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala:
##########
@@ -2596,4 +2596,113 @@ class CollectionExpressionsSuite extends SparkFunSuite
with ExpressionEvalHelper
Date.valueOf("2017-02-12")))
}
}
+
+ test("ArrayAppend Expression Test") {
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(null, ArrayType(StringType)),
+ Literal.create("c", StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(null, ArrayType(StringType)),
+ Literal.create(null, StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(""), ArrayType(StringType)),
+ Literal.create(null, StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(Double.NaN, 1d, 2d), ArrayType(DoubleType)),
+ Literal.create(3d, DoubleType)),
+ Seq(Double.NaN, 1d, 2d, 3d))
+ // Null entry check
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(null, 1d, 2d), ArrayType(DoubleType)),
+ Literal.create(3d, DoubleType)),
+ Seq(null, 1d, 2d, 3d))
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(
+ Seq(Date.valueOf("2017-04-06"), Date.valueOf("2017-03-23"),
Date.valueOf("2017-03-10")),
Review Comment:
Why test date ?
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala:
##########
@@ -4600,3 +4600,111 @@ 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_(array, element) - Add the element at the end of the array
passed as first
+ argument. Type of element should be similar to type of the elements of
the array.""",
+ examples = """
+ Examples:
+ > SELECT _FUNC_(array('b', 'd', 'c', 'a'), 'd');
+ ["b","d","c","a","d"]
+
Review Comment:
empty line ?
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala:
##########
@@ -2596,4 +2596,113 @@ class CollectionExpressionsSuite extends SparkFunSuite
with ExpressionEvalHelper
Date.valueOf("2017-02-12")))
}
}
+
+ test("ArrayAppend Expression Test") {
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(null, ArrayType(StringType)),
+ Literal.create("c", StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(null, ArrayType(StringType)),
+ Literal.create(null, StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(""), ArrayType(StringType)),
+ Literal.create(null, StringType)),
+ null)
+
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(Double.NaN, 1d, 2d), ArrayType(DoubleType)),
+ Literal.create(3d, DoubleType)),
+ Seq(Double.NaN, 1d, 2d, 3d))
+ // Null entry check
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(Seq(null, 1d, 2d), ArrayType(DoubleType)),
+ Literal.create(3d, DoubleType)),
+ Seq(null, 1d, 2d, 3d))
+ checkEvaluation(
+ ArrayAppend(
+ Literal.create(
+ Seq(Date.valueOf("2017-04-06"), Date.valueOf("2017-03-23"),
Date.valueOf("2017-03-10")),
Review Comment:
Why test date ?
--
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]