Order by value in spark pair RDD

后端 未结 2 1449
自闭症患者
自闭症患者 2021-02-18 16:32

I have a spark pair RDD (key, count) as below

Array[(String, Int)] = Array((a,1), (b,2), (c,1), (d,3))

Using spark scala API how to get a new p

2条回答
  •  终归单人心
    2021-02-18 17:10

    This should work:

    //Assuming the pair's second type has an Ordering, which is the case for Int
    rdd.sortBy(_._2) // same as rdd.sortBy(pair => pair._2)
    

    (Though you might want to take the key to account too when there are ties.)

提交回复
热议问题