I am using Scala and Spark to unpivot a table which looks like as below:
+---+----------+--------+-------+------+-----+ | ID| Date | Type1 | Type2 | 0:30 | 1:00| +---+----------+--------+-------+------+-----+ | G| 12/3/2018| Import|Voltage| 3.5 | 6.8 | | H| 13/3/2018| Import|Voltage| 7.5 | 9.8 | | H| 13/3/2018| Export| Watt| 4.5 | 8.9 | | H| 13/3/2018| Export|Voltage| 5.6 | 9.1 | +---+----------+--------+-------+------+-----+ I want to transpose it as follow:
| ID|Date | Time|Import-Voltage |Export-Votage|Import-Watt|Export-Watt| | G|12/3/2018|0:30 |3.5 |0 |0 |0 | | G|12/3/2018|1:00 |6.8 |0 |0 |0 | | H|13/3/2018|0:30 |7.5 |5.6 |0 |4.5 | | H|13/3/2018|1:00 |9.8 |9.1 |0 |8.9 | And Time and Date columns should be also merged like
12/3/2018 0:30