Search code examples
scalaapache-sparkspark-graphx

Retrieving TriangleCount


I'm trying to retrieve the amount of triangles from a graph using graphX. As I'm new to both Scala and graphX, I'm currently quite stuck.

I'm creating a graph from an edgefile:

1 2
1 3
2 3

This should be 1 triangle.

Next I'm using the build in function val countTriangles = graph.triangleCount.

I've however so far been unable to extract the actual trianglecount from this.


Solution

  • triangleCount counts number of triangles per vertex and returns Graph[Int,Int], so you have to extract vertices:

    scala>  graph.triangleCount().vertices.collect()
    res0: Array[(org.apache.spark.graphx.VertexId, Int)] = Array((1,1), (3,1), (2,1))