如何按列在星火SQL降序排序? [英] How to sort by column in descending order in Spark SQL?
本文介绍了如何按列在星火SQL降序排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试过 df.orderBy(COL1)。秀(10)
,但按升序排序。 df.sort(COL1)。秀(10)
也降序排序。我看着计算器上,我找到了答案都是过时或简称RDDS 。我想用火花本地数据帧。
I tried df.orderBy("col1").show(10)
but it sorted in ascending order. df.sort("col1").show(10)
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.
推荐答案
这是在<一个href=\"http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.DataFrame\">org.apache.spark.sql.DataFrame为排序
方法:
df.sort($"col1", $"col2".desc)
请注意 $
和 .desc
在排序
的列由结果进行排序。
Note $
and .desc
inside sort
for the column to sort the results by.
这篇关于如何按列在星火SQL降序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文