Skip to content

Commit 6ab8485

Browse files
gatorsmilecloud-fan
authored andcommitted
[SPARK-26169] Create DataFrameSetOperationsSuite
## What changes were proposed in this pull request? Create a new suite DataFrameSetOperationsSuite for the test cases of DataFrame/Dataset's set operations. Also, add test cases of NULL handling for Array Except and Array Intersect. ## How was this patch tested? N/A Closes apache#23137 from gatorsmile/setOpsTest. Authored-by: gatorsmile <[email protected]> Signed-off-by: Wenchen Fan <[email protected]>
1 parent 6339c8c commit 6ab8485

File tree

3 files changed

+535
-478
lines changed

3 files changed

+535
-478
lines changed

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,19 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
16581658
assert(ArrayExcept(a24, a22).dataType.asInstanceOf[ArrayType].containsNull === true)
16591659
}
16601660

1661+
test("Array Except - null handling") {
1662+
val empty = Literal.create(Seq.empty[Int], ArrayType(IntegerType, containsNull = false))
1663+
val oneNull = Literal.create(Seq(null), ArrayType(IntegerType))
1664+
val twoNulls = Literal.create(Seq(null, null), ArrayType(IntegerType))
1665+
1666+
checkEvaluation(ArrayExcept(oneNull, oneNull), Seq.empty)
1667+
checkEvaluation(ArrayExcept(twoNulls, twoNulls), Seq.empty)
1668+
checkEvaluation(ArrayExcept(twoNulls, oneNull), Seq.empty)
1669+
checkEvaluation(ArrayExcept(empty, oneNull), Seq.empty)
1670+
checkEvaluation(ArrayExcept(oneNull, empty), Seq(null))
1671+
checkEvaluation(ArrayExcept(twoNulls, empty), Seq(null))
1672+
}
1673+
16611674
test("Array Intersect") {
16621675
val a00 = Literal.create(Seq(1, 2, 4), ArrayType(IntegerType, false))
16631676
val a01 = Literal.create(Seq(4, 2), ArrayType(IntegerType, false))
@@ -1769,4 +1782,17 @@ class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper
17691782
assert(ArrayIntersect(a20, a21).dataType.asInstanceOf[ArrayType].containsNull === false)
17701783
assert(ArrayIntersect(a23, a24).dataType.asInstanceOf[ArrayType].containsNull === true)
17711784
}
1785+
1786+
test("Array Intersect - null handling") {
1787+
val empty = Literal.create(Seq.empty[Int], ArrayType(IntegerType, containsNull = false))
1788+
val oneNull = Literal.create(Seq(null), ArrayType(IntegerType))
1789+
val twoNulls = Literal.create(Seq(null, null), ArrayType(IntegerType))
1790+
1791+
checkEvaluation(ArrayIntersect(oneNull, oneNull), Seq(null))
1792+
checkEvaluation(ArrayIntersect(twoNulls, twoNulls), Seq(null))
1793+
checkEvaluation(ArrayIntersect(twoNulls, oneNull), Seq(null))
1794+
checkEvaluation(ArrayIntersect(oneNull, twoNulls), Seq(null))
1795+
checkEvaluation(ArrayIntersect(empty, oneNull), Seq.empty)
1796+
checkEvaluation(ArrayIntersect(oneNull, empty), Seq.empty)
1797+
}
17721798
}

0 commit comments

Comments
 (0)