scalaapache-sparkspark-graphx

Graphx Scala Vertices alwayses return me 0


I'm tring to implement this Graphx example:

import org.apache.spark._
import org.apache.spark.graphx._

val conf = new SparkConf().setAppName("GraphX Example")
val sc = new SparkContext(conf)

// Create an RDD of vertices
val verticesRDD = sc.parallelize(Seq((-1L, "nowhere"), (1L, "yahou"), (2L, "sanae"), (3L, "hanane"), (4L, "said"), (5L, "halima")))

// Create an RDD of edges
val edgesRDD = sc.parallelize(Seq(Edge(1L, 3L, "commenter"), Edge(1L, 3L, "suivre"), Edge(2L, 3L, "commenter"), Edge(2L, 5L, "connecter"), Edge(4L, 2L, "connecter")))

// Create the graph with the default vertex
val graph = Graph(verticesRDD, edgesRDD, "nowhere")

graph.vertices.collect.foreach(println)
graph.edges.collect.foreach(println)

val numVertices = graph.numVertices
val numEdges = graph.numEdges

println(s"Number of vertices: $numVertices")
println(s"Number of edges: $numEdges")

and it returns me always 0 on $numVertices

it doesn't seem that something is wrong

PS: In my example i expect the result to be 6


Solution

  • The issue finally was with:

    val conf = new SparkConf(). setAppName("GraphX Example") val sc = new SparkContext(conf)

    so when i use it two times in a spark-shell it shutdowns automaticlly

    the solution is that i restart my machine and rexecute the script without these two lines and it worked, thank you all