Processing graphs using Graph X
A graph is combination of vertices and edges. Spark provides a module to define a graph and then process these graphs in real time. In this recipe, we are going to look at a social graph example and process data using Spark.
Getting ready
To perform this recipe, you should have Hadoop and Spark installed. You also need to install Scala. I am using Scala 2.11.0 here.
How to do it...
Take a social networking site that has users and other users such as the activities of a user. Based on the likes, we can conclude who is connected to whom. Consider the following data:
Now, we have to analyze this graph based on the likes that are provided. In order to do so, we start the Spark Shell, and run the following commands:
Import graph libraries like this:
scala>import org.apache.spark.graphx._ scala>import org.apache.spark.rdd.RDD
Next, we define vertices and edges:
scala>valvertexArray = Array(
(1L, ("Alice", 28)), (2L, ("Bob", 27)), (3L,...