dongjoon-hyun commented on a change in pull request #23867: [SPARK-26965][SQL]
Makes ElementAt nullability more precise
URL: https://github.com/apache/spark/pull/23867#discussion_r261481806
##########
File path:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollectionExpressionsSuite.scala
##########
@@ -1092,6 +1092,58 @@ class CollectionExpressionsSuite extends SparkFunSuite
with ExpressionEvalHelper
checkEvaluation(ElementAt(mb0, Literal(Array[Byte](3, 4))), null)
}
+ test("correctly handles ElementAt nullability for arrays") {
+ // CreateArray case
+ val a = AttributeReference("a", IntegerType, nullable = false)()
+ val b = AttributeReference("b", IntegerType, nullable = true)()
+ val array = CreateArray(a :: b :: Nil)
+ assert(!ElementAt(array, Literal(0)).nullable)
+ assert(ElementAt(array, Literal(1)).nullable)
+ assert(!ElementAt(array, Subtract(Literal(2), Literal(2))).nullable)
+ assert(ElementAt(array, AttributeReference("ordinal",
IntegerType)()).nullable)
+
+ // GetArrayStructFields case
+ val f1 = StructField("a", IntegerType, nullable = false)
+ val f2 = StructField("b", IntegerType, nullable = true)
+ val structType = StructType(f1 :: f2 :: Nil)
+ val c = AttributeReference("c", structType, nullable = false)()
+ val inputArray1 = CreateArray(c :: Nil)
+ val inputArray1ContainsNull = c.nullable
+ val stArray1 = GetArrayStructFields(inputArray1, f1, 0, 2,
inputArray1ContainsNull)
+ assert(!ElementAt(stArray1, Literal(0)).nullable)
+ val stArray2 = GetArrayStructFields(inputArray1, f2, 1, 2,
inputArray1ContainsNull)
+ assert(ElementAt(stArray2, Literal(0)).nullable)
+
+ val d = AttributeReference("d", structType, nullable = true)()
+ val inputArray2 = CreateArray(c :: d :: Nil)
+ val inputArray2ContainsNull = c.nullable || d.nullable
+ val stArray3 = GetArrayStructFields(inputArray2, f1, 0, 2,
inputArray2ContainsNull)
+ assert(!ElementAt(stArray3, Literal(0)).nullable)
+ assert(ElementAt(stArray3, Literal(1)).nullable)
+ val stArray4 = GetArrayStructFields(inputArray2, f2, 1, 2,
inputArray2ContainsNull)
+ assert(ElementAt(stArray4, Literal(0)).nullable)
+ assert(ElementAt(stArray4, Literal(1)).nullable)
+ }
+
+ test("SPARK-26965 correctly handles ElementAt nullability for maps") {
Review comment:
Ur, ditto. `SPARK-26965`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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]