imen imen - 1 year ago 70
Scala Question

get vertexId graphx

I am new in spark-graphx and scala.
How I could get the id of a vertex in graphx?

This my code:

val sourceVertex=graph.vertices.filter { case (id,(_,_,_,_,_)) => id == 0} // The source vertex

I noticed that c is not the id of sourceVertex(c=21 and not 0)

Any ideas?
Many thanks

Answer Source

The ID you're getting, is not the VertexID but the id() function of RDD

A unique ID for this RDD (within its SparkContext).

Since you're expecting to find only one vertex, you can do it using first like this :

val sourceVertex=graph.vertices.filter { case (id,(_,_,_,_,_)) => id == 0}.first
val c=sourceVertex._1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download