Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Spark-split array to separate column

avatar

Hi all,

Can someone please tell me how to split array into separate column in spark dataframe.

Example:

Df:

A|B

-------

1|(a,b,c,d)

2|(e,f)

Output:

A|col1|col2|col3|col4

------------

1|a|b|c|d

2|e|F| |

Thanks

Manivel k

2 REPLIES 2

avatar

@Mani

Please check this link and let me know if that helps:

https://stackoverflow.com/questions/39255973/split-1-column-into-3-columns-in-spark-scala

https://stackoverflow.com/questions/39235704/split-spark-dataframe-string-column-into-multiple-colum...

HTH

*** If you found this answer addressed your question, please take a moment to login and click the "accept" link on the answer.

avatar

Hi albani,

Thanks for sharing the links, i found these threads earlier. These static one(defined for 3 elements).

I would expect more dynamic. Eg: Today i may receive 3 elements, tomorrow may be 10 elements. Code should handle it dynamically.