@@ -24,25 +24,37 @@ import org.apache.spark.sql.types._
2424
2525class CollectionExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
2626
27- test( " Array and Map Size " ) {
27+ def testSize ( legacySizeOfNull : Boolean , sizeOfNull : Any ) : Unit = {
2828 val a0 = Literal .create(Seq (1 , 2 , 3 ), ArrayType (IntegerType ))
2929 val a1 = Literal .create(Seq [Integer ](), ArrayType (IntegerType ))
3030 val a2 = Literal .create(Seq (1 , 2 ), ArrayType (IntegerType ))
3131
32- checkEvaluation(Size (a0), 3 )
33- checkEvaluation(Size (a1), 0 )
34- checkEvaluation(Size (a2), 2 )
32+ checkEvaluation(Size (a0, legacySizeOfNull ), 3 )
33+ checkEvaluation(Size (a1, legacySizeOfNull ), 0 )
34+ checkEvaluation(Size (a2, legacySizeOfNull ), 2 )
3535
3636 val m0 = Literal .create(Map (" a" -> " a" , " b" -> " b" ), MapType (StringType , StringType ))
3737 val m1 = Literal .create(Map [String , String ](), MapType (StringType , StringType ))
3838 val m2 = Literal .create(Map (" a" -> " a" ), MapType (StringType , StringType ))
3939
40- checkEvaluation(Size (m0), 2 )
41- checkEvaluation(Size (m1), 0 )
42- checkEvaluation(Size (m2), 1 )
40+ checkEvaluation(Size (m0, legacySizeOfNull), 2 )
41+ checkEvaluation(Size (m1, legacySizeOfNull), 0 )
42+ checkEvaluation(Size (m2, legacySizeOfNull), 1 )
43+
44+ checkEvaluation(
45+ Size (Literal .create(null , MapType (StringType , StringType )), legacySizeOfNull),
46+ expected = sizeOfNull)
47+ checkEvaluation(
48+ Size (Literal .create(null , ArrayType (StringType )), legacySizeOfNull),
49+ expected = sizeOfNull)
50+ }
51+
52+ test(" Array and Map Size - legacy" ) {
53+ testSize(legacySizeOfNull = true , sizeOfNull = - 1 )
54+ }
4355
44- checkEvaluation( Size ( Literal .create( null , MapType ( StringType , StringType ))), - 1 )
45- checkEvaluation( Size ( Literal .create( null , ArrayType ( StringType ))), - 1 )
56+ test( " Array and Map Size " ) {
57+ testSize(legacySizeOfNull = false , sizeOfNull = null )
4658 }
4759
4860 test(" MapKeys/MapValues" ) {
0 commit comments