Get all nodes connected to node in Apache Spark GraphX

Suppose we got an entry in Apache GraphX ​​as:

Top RDD:

val vertexArray = Array( (1L, "Alice"), (2L, "Bob"), (3L, "Charlie"), (4L, "David"), (5L, "Ed"), (6L, "Fran") ) 

Edge RDD:

 val edgeArray = Array( Edge(1L, 2L, 1), Edge(2L, 3L, 1), Edge(3L, 4L, 1), Edge(5L, 6L, 1) ) 

I need all the node related components in Apache Spark GraphX

 1,[1,2,3,4] 5,[5,6] 
+6
source share
1 answer

You can use ConnectedComponents , which returns

a graph with a vertex value containing the smallest vertex identifier in the associated component containing that vertex.

and change the results

 graph.connectedComponents.vertices.map(_.swap).groupByKey 
+8
source

All Articles