Skip to content

Commit 3c8a795

Browse files
author
pierre-borckmans
committed
ADD unit test for accessing null elements in array fields
1 parent b6a79e7 commit 3c8a795

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/DataFrameComplexTypeSuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,12 @@ class DataFrameComplexTypeSuite extends QueryTest with SharedSQLContext {
4343
val df = sparkContext.parallelize(Seq((1, 1))).toDF("a", "b")
4444
df.select(array($"a").as("s")).select(f(expr("s[0]"))).collect()
4545
}
46+
47+
test("Accessing null element in array field") {
48+
val df = sc.parallelize(Seq((Seq("val1",null,"val2"),Seq(Some(1),None,Some(2))))).toDF("s","i")
49+
val nullStringRow = df.selectExpr("s[1]").collect()(0)
50+
assert(nullStringRow == org.apache.spark.sql.Row(null))
51+
val nullIntRow = df.selectExpr("i[1]").collect()(0)
52+
assert(nullIntRow == org.apache.spark.sql.Row(null))
53+
}
4654
}

0 commit comments

Comments
 (0)