【发布时间】:2015-05-04 10:28:00
【问题描述】:
我有一个RDD[(VertexId, Double)],我想按_._2 对其进行排序,并用这个RDD 加入索引(排名)。因此,我可以通过filter 获得一个元素及其排名。
目前我按sortBy 对RDD 进行排序,但我不知道如何将RDD 加入其排名。所以我把它作为一个序列收集起来,并用它的索引压缩它。但这不是有效的。我想知道是否有更优雅的方式来做到这一点。
我现在使用的代码是:
val tmpRes = graph.vertices.sortBy(_._2, ascending = false) // Sort all nodes by its PR score in descending order
.collect() // collect to master, this may be very expensive
tmpRes.zip(tmpRes.indices) // zip with index
【问题讨论】:
标签: scala apache-spark rdd