2017-12-11 15 views
0

내가- sortBy 대 sortWith을

// 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)

답변

1

당신이 .collect 처음 일을하고 있기 때문에, 당신은 아닌 RDD에, 만일 Array.sortBy을 요구하고있다. ArraysortBy 메서드는 매개 변수 하나만 사용합니다 (ascending을 지정할 수 없음).

일반적으로 스파크는 최대한 많은 계산을 처리해야하며 끝에는 collect (또는 take) 만 사용해야합니다. 시도해보십시오.

gGraph.inDegrees.sortBy(_._2, ascending=false).take(10) 
+0

예, 작동합니다. 감사! 스칼라> gGraph.inDegrees.sortBy (_._ 2, 오름차순 = false) .take (10) res122 : Array [(org.apache.spark.graphx.VertexId, Int)] = 배열 ​​((10397,152), ((1128, 132), (12266,107), (13487,96), (12892,82), (11618,82), (11433,81), (14869, 80)) – DanJoe