EdgeTriplet Class
An edge triplet represents an edge along with the vertex attributes of its neighboring vertices.
VD: the type of the vertex attribute.
ED: the type of the edge attribute
instance constructor:
new EdgeTriplet()
1
var attr: ED
2
The attribute associated with the edge
3
​
4
var dstAttr: VD
5
The destination vertex attribute
6
​
7
var dstId: VertexId
8
The vertex id of the target vertex
9
​
10
def otherVertexAttr(vid: VertexId): VD
11
Given one vertex in the edge return the other vertex.
12
​
13
def otherVertexId(vid: VertexId): VertexId
14
Given one vertex in the edge return the other vertex.
15
​
16
def relativeDirection(vid: VertexId): EdgeDirection
17
Return the relative direction of the edge to the corresponding vertex.
18
​
19
var srcAttr: VD
20
The source vertex attribute
21
​
22
var srcId: VertexId
23
The vertex id of the source vertex
24
​
25
def toString(): String
26
def
27
toTuple: ((VertexId, VD), (VertexId, VD), ED)
28
​
29
def vertexAttr(vid: VertexId): VD
30
Get the vertex object for the given vertex in the edge
31
​
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
graph.triplets.getClass
19
/*
20
res233: Class[_ <: org.apache.spark.rdd.RDD[org.apache.spark.graphx.EdgeTriplet[(String, String),String]]] = class org.apache.spark.rdd.MapPartitionsRDD
21
graph.triplets is an instance of EdgeTriplet
22
​
23
*/
24
​
25
// Build the initial Graph
26
val facts: RDD[String] =
27
graph.triplets.map((triplet =>
28
triplet.srcAttr._1 + " is the " + triplet.attr + " of " + triplet.dstAttr._1))
29
facts.collect.foreach(println(_))
Copied!
Reference:
Last modified 1yr ago
Copy link