ueshin commented on a change in pull request #25728: [SPARK-29020][WIP][SQL]
Improving array_sort behaviour
URL: https://github.com/apache/spark/pull/25728#discussion_r345376321
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/HigherOrderFunctionsSuite.scala
##########
@@ -162,6 +171,49 @@ class HigherOrderFunctionsSuite extends SparkFunSuite
with ExpressionEvalHelper
Seq("[1, 3, 5]", null, "[4, 6]"))
}
+ test("ArraySort") {
+ val a0 = Literal.create(Seq(2, 1, 3), ArrayType(IntegerType))
+ val a1 = Literal.create(Seq[Integer](), ArrayType(IntegerType))
+ val a2 = Literal.create(Seq("b", "a"), ArrayType(StringType))
+ val a3 = Literal.create(Seq("b", null, "a"), ArrayType(StringType))
+ val d1 = new Decimal().set(10)
+ val d2 = new Decimal().set(100)
+ val a4 = Literal.create(Seq(d2, d1), ArrayType(DecimalType(10, 0)))
+ val a5 = Literal.create(Seq(null, null), ArrayType(NullType))
+
+ val typeAS = ArrayType(StructType(StructField("a", IntegerType) :: Nil))
+ val arrayStruct = Literal.create(Seq(create_row(2), create_row(1)), typeAS)
+
+ val typeAA = ArrayType(ArrayType(IntegerType))
+ val aa1 = Array[java.lang.Integer](1, 2)
+ val aa2 = Array[java.lang.Integer](3, null, 4)
+ val arrayArray = Literal.create(Seq(aa2, aa1), typeAA)
+
+ val typeAAS = ArrayType(ArrayType(StructType(StructField("a", IntegerType)
:: Nil)))
+ val aas1 = Array(create_row(1))
+ val aas2 = Array(create_row(2))
+ val arrayArrayStruct = Literal.create(Seq(aas2, aas1), typeAAS)
+
+ checkEvaluation(arraySort(a0), Seq(1, 2, 3))
+ checkEvaluation(arraySort(a1), Seq[Integer]())
+ checkEvaluation(arraySort(a2), Seq("a", "b"))
+ checkEvaluation(arraySort(a3), Seq("a", "b", null))
+ checkEvaluation(arraySort(a4), Seq(d1, d2))
+ checkEvaluation(arraySort(a5), Seq(null, null))
+ checkEvaluation(arraySort(arrayStruct), Seq(create_row(1), create_row(2)))
+ checkEvaluation(arraySort(arrayArray), Seq(aa1, aa2))
+ checkEvaluation(arraySort(arrayArrayStruct), Seq(aas1, aas2))
+
+ checkEvaluation(arraySort(a0, (left, right) =>
UnaryMinus(ArraySort.comparator(left, right))),
+ Seq(3, 2, 1))
+ checkEvaluation(arraySort(a3, (left, right) =>
UnaryMinus(ArraySort.comparator(left, right))),
+ Seq(null, "b", "a"))
+ checkEvaluation(arraySort(a4, (left, right) =>
UnaryMinus(ArraySort.comparator(left, right))),
+ Seq(d2, d1))
+
+
Review comment:
nit: remove extra lines.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]