I have a DataFrame in spark which looks like this:
+------+-----+-----+-----+
| name | id1 | id2 | id3 |
+------+-----+-----+-----+
| Bob | 1 | 10 | 100 |
| Jill | 2 | 20 | 200 |
| Sue | 3 | 30 | 300 |
| Lane | 4 | 40 | 400 |
+------+-----+-----+-----+
I want to sort of explode
the id columns like so:
+------+----------+---------+
| name | id_value | id_type |
+------+----------+---------+
| Bob | 1 | id1 |
| Bob | 10 | id2 |
| Bob | 100 | id3 |
| Jill | 2 | id1 |
| Jill | 20 | id2 |
| Jill | 200 | id3 |
| Sue | 3 | id1 |
| Sue | 30 | id2 |
| Sue | 300 | id3 |
| Lane | 4 | id1 |
| Lane | 40 | id2 |
| Lane | 400 | id3 |
+------+----------+---------+
I'm using the scala api. Is there a good way to do this? I've looked at the explode
and arrays_zip
functions, but not really sure if that's barking up the right tree.