Creating your first Graph (RDD API)
For the RDD API, the basic class in GraphX is called a Graph
(org.apache.spark.graphx.Graph
), which contains two types of RDDs as you might have guessed:
- Edges
- Vertices
In the following graph, you can see we have a number of different vertices, namely Fawad, Aznan, Ben, Tom, and Marathon.
Figure 7.6: Depiction of a graph
This is a labeled graph where the edges and vertices have labels associated with them.
Following the Graph, we will look at a code example, where we:
- Create the vertices
- Create the edges
- Instantiate a graph object
- View the vertices configured with the graph
The following code example can be used to create a Graph similar to the one shown in the preceding figure.
Code samples
Let's look at the code example:
import org.apache.spark.graphx._ val myVertices = sc.parallelize(Array( (1L, "Fawad"), (2L, "Aznan"), (3L, "Ben"), (4L, "Tom"), (5L, "Marathon")) ) val myEdges =...