EdgeDirection Class
The direction of a directed edge relative to a vertex.
1
def equals(o: Any): Boolean
2
def hashCode(): Int
3
def reverse: EdgeDirection
4
def toString(): String
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
graph.collectNeighborIds(EdgeDirection.Either).take(5).foreach(println)
22
​
23
/*
24
Output:
30
​
31
*/
Copied!
References:
Last modified 1yr ago
Copy link