joinVertices
若graph頂點的Id在點集pointTest中,則將graph頂點的屬性使替換爲點集pointTest的點屬性;
若graph頂點Id不在點集pointTest中,則不對graph頂點屬性做任何修改。
1.創建graph
scala> val graph = GraphLoader.edgeListFile(sc, "file:///home/hadoop/1.txt")
scala> graph.triplets.collect.foreach(println(_))
2.自定義pointTest點集
scala> val pointTest: RDD[(VertexId,Int)] = sc.parallelize(Array((1L,10),(2L,10),(3L,10)))
3.將graph頂點屬性置爲零;joinVertices:
scala> val outputGraph = graph.mapVertices((id,attr) => 0).joinVertices(pointTest)((_,_,optDeg) => optDeg)
scala> outputGraph.triplets.collect.foreach(println(_))
4.outJoinVertices
scala> val outputGraph = graph.mapVertices((id,attr) => 0).outerJoinVertices(pointTest)((_,_,optDeg) => optDeg.getOrElse(0))
—————————–
將頂點屬性改爲各點出度:
scala> val outputGraph = graph.mapVertices((id,attr) => 0).outerJoinVertices(graph.outDegrees)((_,_,optDeg) => optDeg.getOrElse(0))