https://stackoverflow.com/questions/37471346/automatically-and-elegantly-flatten-dataframe-in-spark-sql
The short answer is, there's no "accepted" way to do this, but you
can do it very elegantly with a recursive function that generates your
select(...) statement by walking through the DataFrame.schema .The recursive function should return an Array[Column] . Every time the function hits a StructType , it would call itself and append the returned Array[Column] to its own Array[Column] .Something like:
You would then use it like this:
|
No comments:
Post a Comment