MGHawes 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_r318357528
 
 

 ##########
 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:
   I can if people want me to? My general rule is only to assert exactly what 
the unit test is trying to test. In this case a specific bug. If unit tests are 
overlapping it can be very hard to tell what exactly is failing and where a 
regression has been introduced because all test fail at once.

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