【问题标题】:Graphx Scala Vertices alwayses return me 0Graphx Scala 顶点总是返回我 0
【发布时间】:2023-01-30 01:26:10
【问题描述】:

我正在尝试实现这个 Graphx 示例:

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")

它在$numVertices 上总是返回 0

似乎没有什么不对劲

PS:在我的示例中,我希望结果为 6

【问题讨论】:

  • 我无法重现您的问题。您使用的是什么版本的火花?
  • 在 spark 2.3.1 中工作正常。
  • 我使用火花 1.6.0

标签: scala apache-spark spark-graphx


【解决方案1】:

问题最终在于:

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

所以当我在 spark-shell 中使用它两次时它会自动关闭

解决方案是我重新启动我的机器并在没有这两行的情况下执行脚本并且它有效,谢谢大家

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-27
    • 2014-03-20
    • 2013-04-13
    • 2013-03-30
    • 2016-07-13
    • 2023-04-09
    相关资源
    最近更新 更多