I have a DataFrame which goes on like this :
+---------+-------------+--------------------+--------+ | ID | reg_num| reg_typ|reg_code| +---------+-------------+--------------------+--------+ |523528690| 134886307000|Chamber of Commer | 14246| |523528690|2015 / 369956|Government Gazett | 14225| |523528690| 997253630|Tax Registration | 14259| |523528691| 997253633|Tax Doc | 14250| |523528691| 997253634|Tax File | 14251| |523528691| 997253635|Tax Data | 14252| |523528691| 997253636|Tax Monitor | 14253| +---------+-------------+--------------------+--------+ Now I'm trying to achieve an output with the format as :
+---------+-------------+--------------------+--------+-------------+-------------+-------------+-------------+ | ID | reg_num| reg_typ|reg_code| reg_1 | reg_2 | reg_3 | reg_4 | +---------+-------------+--------------------+--------+-------------+-------------+-------------+-------------+ |523528690| 134886307000|Chamber of Commer | 14246| 134886307000|2015 / 369956| 997253630 | null | |523528690|2015 / 369956|Government Gazett | 14225|134886307000 |2015 / 369956|997253630 |null | |523528690| 997253630|Tax Registration | 14259| 134886307000|2015 / 369956| 997253630 | null | |523528691| 997253633|Tax Doc | 14250| 997253633| 997253634| 997253635| 997253636| |523528691| 997253634|Tax File | 14251| 997253633| 997253634| 997253635| 997253636| |523528691| 997253635|Tax Data | 14252| 997253633| 997253634| 997253635| 997253636| |523528691| 997253636|Tax Monitor | 14253| 997253633| 997253634| 997253635| 997253636| +---------+-------------+--------------------+--------+-------------+-------------+-------------+-------------+ I have seen predefined functionalities like pivot, however it doesnt seem to fit in my case.
I'm using Spark version 1.6 and Scala version 2.10.5.
Help is appriciated!!