How to arrange my tuple of spark results in descending order using value

I am new to sparks and scala. I need to order my set of result counters, which is similar to (course, score) in descending order. I put below

 val results = ratings.countByValue()
 val sortedResults = results.toSeq.sortBy(_._2)

But still it does not work. Thus, he sorts the results on an account with increasing order. But I need to have it in descending order. Can someone please help me.

Results will be similar below.

(History, 12100),
(Music, 13200),
(Drama, 143000)

But I need to display it as below

(Drama, 143000),
(Music, 13200),
(History, 12100)

thank

+4
source share
2 answers

! RDD sortBy() .

val results = ratings.countByValue()
val sortedRdd = results.sortBy(_._2, false)

//Just to display results from RDD
println(sortedRdd.collect().toList)
+4

.sortWith(_._2 >_._2)

toSeq , , . , o.k. .

0

Source: https://habr.com/ru/post/1668166/


All Articles