aboutsummaryrefslogtreecommitdiff
path: root/docs/graphx-programming-guide.md
diff options
context:
space:
mode:
authorAnkur Dave <ankurdave@gmail.com>2014-01-12 16:58:18 -0800
committerAnkur Dave <ankurdave@gmail.com>2014-01-12 16:58:18 -0800
commit7a4bb863c7c11e22332763081793e4989af8c526 (patch)
treef61fc5e6b144e9c5d5a7415c2a13386089afcded /docs/graphx-programming-guide.md
parent5e35d39e0f26db3b669bc2318bd7b3f9f6c5fc50 (diff)
downloadspark-7a4bb863c7c11e22332763081793e4989af8c526.tar.gz
spark-7a4bb863c7c11e22332763081793e4989af8c526.tar.bz2
spark-7a4bb863c7c11e22332763081793e4989af8c526.zip
Add connected components example to doc
Diffstat (limited to 'docs/graphx-programming-guide.md')
-rw-r--r--docs/graphx-programming-guide.md20
1 files changed, 19 insertions, 1 deletions
diff --git a/docs/graphx-programming-guide.md b/docs/graphx-programming-guide.md
index 52668b07c8..22feccb7ad 100644
--- a/docs/graphx-programming-guide.md
+++ b/docs/graphx-programming-guide.md
@@ -475,6 +475,7 @@ GraphX includes a set of graph algorithms in to simplify analytics. The algorith
[Algorithms]: api/graphx/index.html#org.apache.spark.graphx.lib.Algorithms
## PageRank
+<a name="pagerank"></a>
PageRank measures the importance of each vertex in a graph, assuming an edge from *u* to *v* represents an endorsement of *v*'s importance by *u*. For example, if a Twitter user is followed by many others, the user will be ranked highly.
@@ -503,9 +504,26 @@ val ranksByUsername = users.leftOuterJoin(ranks).map {
println(ranksByUsername.collect().mkString("\n"))
{% endhighlight %}
-
## Connected Components
+The connected components algorithm labels each connected component of the graph with the ID of its lowest-numbered vertex. For example, in a social network, connected components can approximate clusters. We can compute the connected components of the example social network dataset from the [PageRank section](#pagerank) as follows:
+
+{% highlight scala %}
+// Load the implicit conversion and graph as in the PageRank example
+import org.apache.spark.graphx.lib._
+val users = ...
+val followers = ...
+val graph = Graph(users, followers)
+// Find the connected components
+val cc = graph.connectedComponents().vertices
+// Join the connected components with the usernames
+val ccByUsername = graph.vertices.innerJoin(cc) { (id, username, cc) =>
+ (username, cc)
+}
+// Print the result
+println(ccByUsername.collect().mkString("\n"))
+{% endhighlight %}
+
## Shortest Path
## Triangle Counting