I have a dataframe as follows:
+-----------+
| f1 |
+-----------+
|[a,b,c] |
|[e,f,g] |
|[h,i] |
+-----------+
I want to explode it to rows along with a repeated unique number field as follows:
+-----------+--------+
| f1 | uid|
+-----------+--------+
|a | 1|
|b | 1|
|c | 1|
|e | 2|
|f | 2|
|g | 2|
|h | 3|
|i | 3|
+-----------+--------+
I can perform explode directly as explained here - Spark: Explode a dataframe array of structs and append id
but I am not sure on how to add the uid
field to the new dataframe so that each exploded array field would have the same uid
and other elements have different uid
values.