July 2017
Intermediate to advanced
796 pages
18h 55m
English
A triangle is created if two neighbors of a vertex are connected by an edge. In other words, a user will create a triangle with the two friends who are friends with each other.
Graph has a function triangleCount(), which computes the triangles in the graph.
The following is the code used to count the triangles in the graph by first invoking the triangleCount function and then by joining the triangles with the vertices (users) to generate the output of each user and the triangle the user belongs to:
scala> val triangleCounts = graph.triangleCount.verticestriangleCounts: org.apache.spark.graphx.VertexRDD[Int] = VertexRDDImpl[3365] at RDD at VertexRDD.scala:57scala> triangleCounts.take(10)res171: Array[(org.apache.spark.graphx.VertexId, ...
Read now
Unlock full access