Am new to spark, currently am trying to do a pivot from rows to columns without aggregation like i need the data to be duplicated after the pivot.
i have the data like below
+----+----------+--------+
|abc |col |position|
+----+----------+--------+
|1234|183500000X|0 |
|1234|0202211120|1 |
|1234|VA |2 |
|1234|Y |3 |
|1234|183500000X|0 |
|1234|21174 |1 |
|1234|NC |2 |
|1234|N |3 |
|1234|null |0 |
|1234|null |1 |
|1234| |2 |
|1234| |3 |
|1234|null |0 |
|1234|null |1 |
|1234| |2 |
|1234| |3 |
i would like to change it to below format
+----------+----------+----------+---+---+
| abc | 0| 1| 2| 3|
+----------+----------+----------+---+---+
|1234 |183500000X|0202211120| VA| Y|
|1234 |183500000X|21174 | NC| N|
+----------+----------+----------+---+---+
whenever i tried to use df.groupBy($"abc").pivot("position").agg(first($"col")) ... am getting only one record instead of all.
is there a way to get all the records without aggregation.
do i need to join with another dataframe to pull out the data.. kindly suggest me on the same.