Vedom Vedom - 5 months ago 57
Scala Question

How to sort by column in descending order in Spark SQL?

I tried

but it sorted in ascending order.
also sorts in descending order. I looked on stackoverflow and the answers I found were all outdated or referred to RDDs. I'd like to use the native dataframe in spark.


It's in org.apache.spark.sql.DataFrame for sort method:

df.sort($"col1", $"col2".desc)

Note $ and .desc inside sort for the column to sort the results by.