I need to do join/joinVertices or add a field in tuple in graph by Spark Graphx

痴心易碎 提交于 2019-12-06 04:49:12

As I was looking for ((vId_src,src_att),(vId_dst,dst_att),property, ccID) so I used zip() for two RDDs.

 val cc: Graph[graphx.VertexId,String] = propGraph.connectedComponents().cache()
    println("###GRAPH WITH CONNECTED COMPONENTS ###")
    cc.triplets.foreach(println(_))
    println("###VERTICES OF CONNECTED COMPONENTS GRAPH ###")
    cc.vertices.foreach(println(_))
    println("###EDGES OF CONNECTED COMPONENTS GRAPH  ###")
    cc.edges.foreach(println(_))


/**
 * Alternative way for join operation*/
println("###STEP-2 GETTING ONE MERGED RDD OF NEW GRAPH###")
val newGraph: RDD[String] = propGraph.triplets.map(t =>t.srcId +","+ t.srcAttr+"),"+"("+t.dstId+","+ t.dstAttr+"),"+t.attr)
val ccID: RDD[String]=cc.triplets.map(t=>t.srcAttr+"")
val newPropGraph: RDD[(String,String)]= newGraph.zip(ccID)
newPropGraph.collect.foreach(println(_))

After doing so I got following as output:

(4294967296,<http://umkc.edu/xPropGraph#node1>),(2147483649,<http://umkc.edu/xPropGraph#node2>),<http://umkc.edu/xPropGraph#prop1>,0)
(2147483649,<http://umkc.edu/xPropGraph#node2>),(6442450942,<http://umkc.edu/xPropGraph#node4>),<http://umkc.edu/xPropGraph#prop5>,0)
(4294967295,<http://umkc.edu/xPropGraph#node5>),(2147483648,<http://umkc.edu/xPropGraph#node6>),<http://umkc.edu/xPropGraph#prop3>,2147483648)
(0,<http://umkc.edu/xPropGraph#node3>),(6442450942,<http://umkc.edu/xPropGraph#node4>),<http://umkc.edu/xPropGraph#prop2>,0)
(2147483649,<http://umkc.edu/xPropGraph#node2>),(0,<http://umkc.edu/xPropGraph#node3>),<http://umkc.edu/xPropGraph#prop4>,0)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!