GraphX is Spark's approach to graphs and computation against graphs. In this recipe, we will see a preview of what is possible with the GraphX component in Spark.
Now that we have the Twitter data stored in the ElasticSearch index, we will perform the following tasks on this data using a graph:
Convert the ElasticSearch data into a Spark Graph.
Sample vertices, edges, and triplets in the graph.
Find the top group of connected hashtags (connected component).
List all the hashtags in that component.
Converting the ElasticSearch data into a graph: This involves two steps:
Converting ElasticSearch data into a DataFrame: This step, like we saw in an earlier recipe, is just a one-liner:
def convertElasticSearchDataToDataFrame(sqlContext: SQLContext) = { val twStatusDf = sqlContext.esDF("spark/twstatus") twStatusDf }
Converting DataFrame to a graph: Spark Graph construction requires an RDD for a vertex and an RDD of edges. Let's construct them...