Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/17226#discussion_r105322903
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/DataFramePivotSuite.scala ---
@@ -216,4 +216,18 @@ class DataFramePivotSuite extends QueryTest with
SharedSQLContext{
Row("d", 15000.0, 48000.0) :: Row("J", 20000.0, 30000.0) :: Nil
)
}
+
+ test("pivot with null should not throw NPE") {
+ checkAnswer(
+ Seq(Tuple1(None),
Tuple1(Some(1))).toDF("a").groupBy($"a").pivot("a").count(),
+ Row(null, 1, null) :: Row(1, null, 1) :: Nil)
+ }
+
+ test("pivot with null and aggregate type not supported by PivotFirst
returns correct result") {
+ checkAnswer(
+ Seq(Tuple1(None), Tuple1(Some(1))).toDF("a")
+ .withColumn("b", expr("array(a, 7)"))
+ .groupBy($"a").pivot("a").agg(min($"b")),
--- End diff --
I just checked they are different to help verify.
```scala
Seq(Tuple1(None),
Tuple1(Some(1))).toDF("a").groupBy($"a").pivot("a").count()
```
- optimized
```
+----+----+----+
| a|null| 1|
+----+----+----+
|null| 1|null|
| 1|null| 1|
+----+----+----+
```
- non-optimized
```
+----+----+---+
| a|null| 1|
+----+----+---+
|null| 1| 0|
| 1| 0| 1|
+----+----+---+
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]