I am trying to see if we can create new columns from value in one of the columns in a dataFrame using spark/scala. I have a dataframe with following data in it
df.show()
+---+-----------------------+
|id |allvals |
+---+-----------------------+
|1 |col1,val11|col3,val31 |
|3 |col3,val33|col1,val13 |
|2 |col2,val22 |
+---+-----------------------+
In the above data col1/col2/col3 are the column names followed by it's value. Column name and value are separated by ,
. Each set is separated by |
.
Now, I want to achieve like this
+---+----------------------+------+------+------+
|id |allvals |col1 |col2 |col3 |
+---+----------------------+------+------+------+
|1 |col1,val11|col3,val31 |val11 |null |val31 |
|3 |col3,val33|col1,val13 |val13 |null |val13 |
|2 |col2,val22 |null |val22 |null |
+---+----------------------+------+------+------+
Appreciate any help.