Vedom Vedom - 1 year ago 180
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download