, 당신은 다음과 같이 뭔가를 시도 할 수 있습니다 :
import org.apache.spark.rdd.RDD
import org.apache.spark.graphx.Edge
// Sample data
val rdd = sc.parallelize(Seq("1: 1, 2, 3", "2: 2, 3"))
val edges: RDD[Edge[Int]] = rdd.flatMap {
row =>
// split around ":"
val splitted = row.split(":").map(_.trim)
// the value to the left of ":" is the source vertex:
val srcVertex = splitted(0).toLong
// for the values to the right of ":", we split around "," to get the other vertices
val otherVertices = splitted(1).split(",").map(_.trim)
// for each vertex to the right of ":", we create an Edge object connecting them to the srcVertex:
otherVertices.map(v => Edge(srcVertex, v.toLong, 1))
}
편집
또한, 당신의 정점이 일정한 기본 가중치가있는 경우, 가장자리에서 바로 그래프를 만들 수 있으므로 꼭짓점을 만들 필요가 없습니다.
import org.apache.spark.graphx.Graph
val g = Graph.fromEdges(edges, defaultValue = 1)
th 당신의 모든 도움을 얻을 수 있습니다 !! 나는 당신이 말한 것을 따라 갔고, val graph를 만들 수 있었고, 그것이 효과가 있는지보기위한 방법을 찾기 위해 노력했습니다! –
나는 당신이 말한 방식대로 해봤지만, 작동하지 않는 것은 RDD뿐입니다. [Edge [Int] 그래서 RDD를 사용했습니다. 그러나 다음 오류가 계속 발생합니다. : 43 : 오류 : 찾을 수 없음 : 값 Edge otherVertices.map ^ : 43 : 오류 : 형식이 일치하지 않습니다. found : Array [없음] 필요 : TraversableOnce [?] otherVertices.map (v => Edge (srcVertex, v.toLong, 1)) –
Edge 클래스를 가져 왔습니까? 'import org.apache.spark.graphx.Edge'. 그게 아마도 문제이고 또한 RDD [Edge [Int]]가 작동하지 않는 이유입니다. –