Spark Graphx 度数排序 - sortBy 与 sortWith
Spark Graphx inDegrees Sorting - sortBy Vs sortWith
我正在尝试根据 Spark Graph 中的度数对顶点列表进行排序(使用 Scala)
// Sort Ascending - both the 2 below yeild same results
gGraph.inDegrees.collect.sortBy(_._2).take(10)
gGraph.inDegrees.collect.sortWith(_._2 < _._2).take(10)
// Sort Decending
gGraph.inDegrees.collect.sortWith(_._2 > _._2).take(10)
gGraph.inDegrees.collect.sortBy(_._2, ascending=false).take(10) //Doesnt Work!!
我希望 sortBy(_._2, ascending=false)
的结果与上面提到的 sortWith(_._2>_._2)
相同。但是出现以下错误。感谢对此的任何想法。谢谢!
scala> gGraph.inDegrees.collect.sortBy(_.2, ascending=false).take(10)
:55: error: too many arguments for method sortBy: (f:
((org.apache.spark.graphx.VertexId, Int)) => B)(implicit ord:
scala.math.Ordering[B])Array[(org.apache.spark.graphx.VertexId, Int)]
gGraph.inDegrees.collect.sortBy(._2, ascending=false).take(10)
由于您首先执行 .collect
,因此您是在 Array
上调用 .sortBy
,而不是在 RDD
上调用 .sortBy
。 Array
的sortBy
方法只有一个参数(不能指定ascending
)。
您通常应该让 spark 处理尽可能多的计算,并且只在最后处理 collect
(或 take
)。试试这个:
gGraph.inDegrees.sortBy(_._2, ascending=false).take(10)
我正在尝试根据 Spark Graph 中的度数对顶点列表进行排序(使用 Scala)
// Sort Ascending - both the 2 below yeild same results
gGraph.inDegrees.collect.sortBy(_._2).take(10)
gGraph.inDegrees.collect.sortWith(_._2 < _._2).take(10)
// Sort Decending
gGraph.inDegrees.collect.sortWith(_._2 > _._2).take(10)
gGraph.inDegrees.collect.sortBy(_._2, ascending=false).take(10) //Doesnt Work!!
我希望 sortBy(_._2, ascending=false)
的结果与上面提到的 sortWith(_._2>_._2)
相同。但是出现以下错误。感谢对此的任何想法。谢谢!
scala> gGraph.inDegrees.collect.sortBy(_.2, ascending=false).take(10) :55: error: too many arguments for method sortBy: (f: ((org.apache.spark.graphx.VertexId, Int)) => B)(implicit ord: scala.math.Ordering[B])Array[(org.apache.spark.graphx.VertexId, Int)] gGraph.inDegrees.collect.sortBy(._2, ascending=false).take(10)
由于您首先执行 .collect
,因此您是在 Array
上调用 .sortBy
,而不是在 RDD
上调用 .sortBy
。 Array
的sortBy
方法只有一个参数(不能指定ascending
)。
您通常应该让 spark 处理尽可能多的计算,并且只在最后处理 collect
(或 take
)。试试这个:
gGraph.inDegrees.sortBy(_._2, ascending=false).take(10)