219CID
219CID

Reputation: 440

Sort every column of a dataframe in spark scala

I am working in Spark & Scala and have a dataframe with several hundred columns. I would like to sort the dataframe by every column. Is there anyway to do this in Scala/Spark?

I have tried:

val sortedDf = actualDF.sort(actualDF.columns)

but .sort does not support Array[String] input.

This question has been asked before: Sort all columns of a dataframe but there is no Scala answer

Upvotes: 2

Views: 1085

Answers (1)

219CID
219CID

Reputation: 440

Thank you to @blackbishop for the answer to this:

val dfSortedByAllItsColumns = actualDF.sort(actualDF.columns.map(col): _*)

Upvotes: 1

Related Questions