val defaultUser = (0,0,0) val graph: Graph[(Int, Int, Int), Int] = Graph(vertexRDD, edgeRDD, defaultUser) val subgraph = graph.subgraph(t => t.attr == 200) val pagerankGraph = subgraph.pageRank(0.001) def printToFile(f: java.io.File)(op: java.io.PrintWriter => Unit) { val p = new java.io.PrintWriter(f) try { op(p) } finally { p.close() } } import java.io._ printToFile(new File("webpages.txt")) { p => for (triplet <- pagerankGraph.triplets.collect) { p.println(triplet.srcId+s" "+triplet.srcAttr) } }