HyukjinKwon commented on a change in pull request #25575: [SPARK-28818][SQL] 
Respect source column nullability in the arrays created by `freqItems()`
URL: https://github.com/apache/spark/pull/25575#discussion_r318358576
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/DataFrameStatSuite.scala
 ##########
 @@ -366,6 +366,27 @@ class DataFrameStatSuite extends QueryTest with 
SharedSparkSession {
     }
   }
 
+  test("SPARK-28818: Respect original column nullability in `freqItems`") {
+    val rows = spark.sparkContext.parallelize(
+      Seq(Row("1", "a"), Row("2", null), Row("3", "b"))
+    )
+    val schema = StructType(Seq(
+      StructField("non_null", StringType, false),
+      StructField("nullable", StringType, true)
+    ))
+    val df = spark.createDataFrame(rows, schema)
+
+    val result = df.stat.freqItems(df.columns)
+
+    val nonNullableFreqItems = 
result.schema("non_null_freqItems").dataType.asInstanceOf[ArrayType]
+    val nullableFreqItems = 
result.schema("nullable_freqItems").dataType.asInstanceOf[ArrayType]
+
+    assert(nonNullableFreqItems.containsNull == false)
+    assert(nullableFreqItems.containsNull == true)
+    // Original bug was a NullPointerException exception caused by calling 
collect(), test for this
+    val resultRows = result.collect()
 
 Review comment:
   Nullability might have been intentionally disabled on purpose. If the 
results are incorrect, there's no point of fixing this NPE.
   
   If you want to keep this to test NPE, can we add another test to assert if 
the results are correct?

----------------------------------------------------------------
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]

Reply via email to