2017-09-25 13 views
0

그래프가 있으며 최대 차수를 계산하고 싶습니다. 특히 최대치를 가진 꼭지점은 모든 속성을 알고 싶습니다. 이 코드의 조각입니다 :스칼라 - 스파크 : 특정 노드에서 정점 특성을 반환하십시오.

def max(a: (VertexId, Int), b: (VertexId, Int)): (VertexId, Int) = { 
    if (a._2 > b._2) a else b 
} 

val maxDegrees : (VertexId, Int) = graphX.degrees.reduce(max) 
max: (a: (org.apache.spark.graphx.VertexId, Int), b: (org.apache.spark.graphx.VertexId, Int))(org.apache.spark.graphx.VertexId, Int) 
maxDegrees: (org.apache.spark.graphx.VertexId, Int) = (2063726182,56387) 

val startVertexRDD = graphX.vertices.filter{case (hash_id, (id, state)) => hash_id == maxDegrees._1} 
startVertexRDD.collect() 

그러나이 예외 반환

org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 145.0 failed 1 times, most recent failure: Lost task 0.0 in stage 145.0 (TID 5380, localhost, executor driver): scala.MatchError: (1009147972,null) (of class scala.Tuple2) 

어떻게 고칠 수 있습니까?

답변

1

이것이 문제라고 생각합니다. 여기 (

(hash_id, (id, state)) 

때문에의 Tuple2을 비교하는 scala.MatchError을 올리기 VertextId을 :

val startVertexRDD = graphX.vertices.filter{case (hash_id, (id, state)) => hash_id == maxDegrees._1} 

는 그래서 이런이

(2063726182,56387) 

기대 무언가 같이 일부 튜플을 비교하려고 , Int) Tuple2 of (VertexId, Tuple2 (id, state))

위와 같이주의해야합니다. L : 구체적으로 여기

org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 145.0 failed 1 times, most recent failure: Lost task 0.0 in stage 145.0 (TID 5380, localhost, executor driver): scala.MatchError: (1009147972,null) (of class scala.Tuple2) 

:

scala.MatchError: (1009147972,null) 

가 정점 1009147972에 대해 계산에는 정도가 없다 그래서 그것뿐만 아니라 몇 가지 문제를 제기 할 수 비교할 때.

희망이 도움이됩니다.

이런 코드 절연 노드가 있다면 I 체크
+0

: 브로 vertexDegree는 : VertexRDD [지능 = graphX.degrees 브로 vertexNoDegree = {vertexDegree.filter 케이스 (ID,도) =>도 == 널} vertexNoDegree.isEmpty() res6 : Boolean = true 격리 된 노드가 없습니다 ... 무엇을 해야할지 모르겠습니다. – alukard990