You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/08/28 00:49:25 UTC

[GitHub] [spark] HyukjinKwon commented on a change in pull request #25575: [SPARK-28818][SQL] Respect source column nullability in the arrays created by `freqItems()`

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_r318353249
 
 

 ##########
 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:
   Can we assert the results as well?

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org