If you want to sort in descending order, and if the corresponding element is of type int, you can use the “-” sign to sort the RDD in descending order.
For ex:
I have an RDD tuple with (String, Int). To sort this RDD by its 2nd element in descending order,
rdd.sortBy(x => -x._2).collect().foreach(println);
I have an RDD tuple with (String, String). To sort this RDD by its 2nd element in descending order,
rdd.sortBy(x => x._2, false).collect().foreach(println);
source share