GraphOps Class
class GraphOps[VD, ED] extends Serializable
Instance constructor:
new GraphOps(graph: Graph[VD, ED])(implicit arg0: ClassTag[VD], arg1: ClassTag[ED])
1
def collectEdges(edgeDirection: EdgeDirection): VertexRDD[Array[Edge[ED]]]
2
​
3
Returns an RDD that contains for each vertex v its local edges, i.e., the edges that are incident on v, in the user-specified direction.
4
​
5
def collectNeighborIds(edgeDirection: EdgeDirection): VertexRDD[Array[VertexId]]
6
​
7
Collect the neighbor vertex ids for each vertex.
8
​
9
def collectNeighbors(edgeDirection: EdgeDirection): VertexRDD[Array[(VertexId, VD)]]
10
​
11
Collect the neighbor vertex attributes for each vertex.
12
​
13
def connectedComponents(maxIterations: Int): Graph[VertexId, ED]
14
​
15
Compute the connected component membership of each vertex and return a graph with the vertex value containing the lowest vertex id in the connected component containing that vertex.
16
​
17
def connectedComponents(): Graph[VertexId, ED]
18
​
19
Compute the connected component membership of each vertex and return a graph with the vertex value containing the lowest vertex id in the connected component containing that vertex.
20
​
21
def convertToCanonicalEdges(mergeFunc: (ED, ED) β‡’ ED = (e1, e2) => e1): Graph[VD, ED]
22
​
23
Convert bi-directional edges into uni-directional ones.
24
​
25
lazy val degrees: VertexRDD[Int]
26
​
27
The degree of each vertex in the graph.
28
​
29
def filter[VD2, ED2](preprocess: (Graph[VD, ED]) β‡’ Graph[VD2, ED2], epred: (EdgeTriplet[VD2, ED2]) β‡’ Boolean = (x: EdgeTriplet[VD2, ED2]) => true, vpred: (VertexId, VD2) β‡’ Boolean = (v: VertexId, d: VD2) => true)(implicit arg0: ClassTag[VD2], arg1: ClassTag[ED2]): Graph[VD, ED]
30
​
31
Filter the graph by computing some values to filter on, and applying the predicates.
32
​
33
lazy val inDegrees: VertexRDD[Int]
34
​
35
The in-degree of each vertex in the graph.
36
​
37
def joinVertices[U](table: RDD[(VertexId, U)])(mapFunc: (VertexId, VD, U) β‡’ VD)(implicit arg0: ClassTag[U]): Graph[VD, ED]
38
​
39
Join the vertices with an RDD and then apply a function from the vertex and RDD entry to a new vertex value.
40
​
41
lazy val numEdges: Long
42
​
43
The number of edges in the graph.
44
​
45
lazy val
46
numVertices: Long
47
The number of vertices in the graph.
48
​
49
lazy val outDegrees: VertexRDD[Int]
50
​
51
The out-degree of each vertex in the graph.
52
​
53
def pageRank(tol: Double, resetProb: Double = 0.15): Graph[Double, Double]
54
​
55
Run a dynamic version of PageRank returning a graph with vertex attributes containing the PageRank and edge attributes containing the normalized edge weight.
56
​
57
def personalizedPageRank(src: VertexId, tol: Double, resetProb: Double = 0.15): Graph[Double, Double]
58
​
59
Run personalized PageRank for a given vertex, such that all random walks are started relative to the source node.
60
​
61
def pickRandomVertex(): VertexId
62
​
63
Picks a random vertex from the graph and returns its ID.
64
​
65
def pregel[A](initialMsg: A, maxIterations: Int = Int.MaxValue, activeDirection: EdgeDirection = EdgeDirection.Either)(vprog: (VertexId, VD, A) β‡’ VD, sendMsg: (EdgeTriplet[VD, ED]) β‡’ Iterator[(VertexId, A)], mergeMsg: (A, A) β‡’ A)(implicit arg0: ClassTag[A]): Graph[VD, ED]
66
​
67
Execute a Pregel-like iterative vertex-parallel abstraction.
68
​
69
def removeSelfEdges(): Graph[VD, ED]
70
​
71
Remove self edges.
72
​
73
def staticPageRank(numIter: Int, resetProb: Double = 0.15): Graph[Double, Double]
74
​
75
Run PageRank for a fixed number of iterations returning a graph with vertex attributes containing the PageRank and edge attributes the normalized edge weight.
76
​
77
def staticParallelPersonalizedPageRank(sources: Array[VertexId], numIter: Int, resetProb: Double = 0.15): Graph[Vector, Double]
78
​
79
Run parallel personalized PageRank for a given array of source vertices, such that all random walks are started relative to the source vertices
80
​
81
def staticPersonalizedPageRank(src: VertexId, numIter: Int, resetProb: Double = 0.15): Graph[Double, Double]
82
​
83
Run Personalized PageRank for a fixed number of iterations with with all iterations originating at the source node returning a graph with vertex attributes containing the PageRank and edge attributes the normalized edge weight.
84
​
85
def stronglyConnectedComponents(numIter: Int): Graph[VertexId, ED]
86
​
87
Compute the strongly connected component (SCC) of each vertex and return a graph with the vertex value containing the lowest vertex id in the SCC containing that vertex.
88
​
89
def triangleCount(): Graph[Int, ED]
90
​
91
Compute the number of triangles passing through each vertex.
92
​
Copied!
Example:
1
import org.apache.spark._
2
import org.apache.spark.graphx._
3
import org.apache.spark.rdd.RDD
4
​
5
// Create an RDD for the vertices
6
val users: RDD[(VertexId, (String, String))] =
7
sc.parallelize(Array((3L, ("rxin", "student")), (7L, ("jgonzal", "postdoc")),
8
(5L, ("franklin", "prof")), (2L, ("istoica", "prof")),
9
(4L, ("peter", "student"))))
10
// Create an RDD for edges
11
val relationships: RDD[Edge[String]] =
12
sc.parallelize(Array(Edge(3L, 7L, "collab"), Edge(5L, 3L, "advisor"),
13
Edge(2L, 5L, "colleague"), Edge(5L, 7L, "pi"),
14
Edge(4L, 0L, "student"), Edge(5L, 0L, "colleague")))
15
// Define a default user in case there are relationship with missing user
16
val defaultUser = ("John Doe", "Missing")
17
​
18
// Build the initial Graph
19
val graph = Graph(users, relationships, defaultUser)
20
​
21
val graph_operation=new GraphOps(graph)
22
val direction: EdgeDirection = EdgeDirection.Out
23
graph_operation.collectNeighborIds(direction).take(5).foreach(println)
24
​
25
/*
26
Output:
32
graph_operation: org.apache.spark.graphx.GraphOps[(String, String),String] = [email protected]
33
direction: org.apache.spark.graphx.EdgeDirection = EdgeDirection.Out
34
​
35
*/
Copied!
Reference:
Last modified 1yr ago
Copy link