Graphx

Basic components of Graph computing:

Graph essentially consistes Vertex, Edge and Triplet, each is an implementation of RDD, therefore, methods that are applied to a RDD can be applied to Vertex RDD, Edge RDD and Triplet RDD. If you want, for example, you can convert Vetex RDD, Edge RDD and Triplet RDD to Spark SQL dataframe and use SQL to manipulate them.

Vetex, Edge and Triplet

Vertex is a 2 element tuple: (vertex id, attribute)

graph.vertices.take(5).foreach(println)

/*
output:
(34,34.0)
(52,52.0)
(96,96.0)
(4,4.0)
(16,16.0)

*/

Edge is a case class, or structure (like a struct in C): Edge(source vertex id, destination vertex id, Edge attribute)

graph.edges.take(5).foreach(println)
/*
Output:
Edge(0,2,1)
Edge(0,3,1)
Edge(0,6,1)
Edge(0,7,1)
Edge(0,13,1)
*/

Triplet is a 3 element nested tuple (tuple in tuple): (source Vertex, destination Vertex, Edge attribute)

graph.triplets.take(5).foreach(println)
/*
Output:
((0,0.0),(2,2.0),1)
((0,0.0),(3,3.0),1)
((0,0.0),(6,6.0),1)
((0,0.0),(7,7.0),1)
((0,0.0),(13,13.0),1)
*/

Graphx contains the classes and others in below packages:

org.apache.spark.graphx

org.apache.spark.graphx.impl

org.apache.spark.graphx.lib

org.apache.spark.graphx.util

Last updated