EnricoMi commented on code in PR #36150:
URL: https://github.com/apache/spark/pull/36150#discussion_r881780193
##########
sql/core/src/test/scala/org/apache/spark/sql/MeltSuite.scala:
##########
@@ -0,0 +1,297 @@
+/*
Review Comment:
Partially! Pivot has an aggregation part, which aggregates values if
multiple values exist for the same groupby and pivot values (see (dotNET,2012)
below). From that aggregated Dataset, you cannot recreate the input.
Formally, the melting of a pivoted Dataset is identical the grouped and
aggregated input Dataset:
```
val courseSales
+------+----+--------+
|course|year|earnings|
+------+----+--------+
|dotNET|2012| 10000.0|
|dotNET|2012| 5000.0|
|dotNET|2013| 48000.0|
| Java|2012| 20000.0|
| Java|2013| 30000.0|
+------+----+--------+
val pivoted = courseSales.groupBy("year").pivot("course", Seq("dotNET",
"Java")).agg(sum($"earnings"))
+----+-------+-------+
|year| dotNET| Java|
+----+-------+-------+
|2012|15000.0|20000.0|
|2013|48000.0|30000.0|
+----+-------+-------+
val melted = pivoted.melt(Array("year"))
+----+--------+-------+
|year|variable| value|
+----+--------+-------+
|2012| dotNET|15000.0|
|2012| Java|20000.0|
|2013| dotNET|48000.0|
|2013| Java|30000.0|
+----+--------+-------+
val expected = courseSales.groupBy("year", "course").sum("earnings")
checkAnswer(melted, expected)
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]