使用 GraphX 中两个 RDD 的边连接前两个节点

Connecting the first two nodes with an edge from two RDDs in GraphX

我是第一次使用 GraphX,我想逐步构建一个 Graph。所以我需要将前两个节点连接到边缘,因为我知道我有 2 个 RDD(每个都有一个值):

firstRDD: RDD[((Int, Array[Int]), ((VertexId, Array[Int]), Int))]
secondRDD: RDD[((Int, Array[Int]), ((VertexId, Array[Int]), Int))]  

我想连接第一个 VertexId 和第二个。 感谢您的帮助

基本上,您使用 mapcase 语句来挑选 VertexId,然后使用 RDD.zip 将它们拼接在一起,然后另一个 map 来创建最终 EdgeRDD:

firstRDD.map{ 
  case ((junk1,junk2), ((vertex1, junk3), junk4)) => vertex1
}.zip(
  secondRDD.map{
    case ((junk1,junk2), ((vertex2, junk3), junk4)) => vertex2 
  }
).map{ case(vertex1, vertex2) => Edge(vertex1, vertex2, 0) }