繁体   English   中英

使用Spark GraphX时发生INT / LONG转换的奇怪错误

[英]Strange bug with INT/LONG conversion when using Spark GraphX

这里是Scala的新开发人员,也是Spark GraphX的新用户。 到目前为止,我真的很喜欢我的时间,但是我刚刚遇到了一个非常奇怪的错误。 我已将问题隔离为长时间转换为int的转换,但这确实很奇怪。 另一个奇怪的事情是,它在Windows中可以正常工作,但在Linux中却不能工作(创建无限循环)。我在Linux中找到了问题的根源,但我不明白为什么会出现问题。 我必须先将随机数放入变量中,然后它才能工作。

您应该能够复制/粘贴并执行整个操作

Scala 2.10.6,Spark 2.1.0,Linux Ubuntu 16.04

 import org.apache.spark.{SparkConf, SparkContext}
  import org.apache.spark.graphx._
  import scala.util.Random

object Main extends App {

  //Fonction template pour imprimer n'importe quel graphe
  def printGraph[VD,ED] ( g : Graph[VD,ED] ): Unit = {
    g.vertices.collect.foreach( println )
  }

  def randomNumber(limit : Int) = {
    val start = 1
    val end   = limit
    val rnd = new Random
    start + rnd.nextInt( (end - start) + 1 )
  }

  val conf = new SparkConf()
    .setAppName("Simple Application")
    .setMaster("local[*]")

  val sc = new SparkContext(conf)
  sc.setLogLevel("ERROR")

  val myVertices = sc.makeRDD(Array((1L, "A"), (2L, "B"), (3L, "C"), (4L, "D"), (5L, "E"), (6L, "F")))

  val myEdges = sc.makeRDD(Array(Edge(1L, 2L, ""),
    Edge(1L, 3L, ""), Edge(1L, 6L, ""), Edge(2L, 3L, ""),
    Edge(2L, 4L, ""), Edge(2L, 5L, ""), Edge(3L, 5L, ""),
    Edge(4L, 6L, ""), Edge(5L, 6L, "")))

  val myGraph = Graph(myVertices, myEdges)

  //Add a random color to each vertice. This random color is chosen from the total number of vertices
  //Transform vertex attribute to color only

  val bug = myVertices.count()
  println("Long : " + bug)
  val bugInt = bug.toInt
  println("Int : " + bugInt)

  //Problem is here when adding myGraph.vertices.count().toInt inside randomNumber. Works on Windows, infinite loop on Linux.
  val g2 = myGraph.mapVertices( ( id, name  ) => ( randomNumber(myGraph.vertices.count().toInt) ))

 //Rest of code removed



}

不知道您在寻找解决方案还是根本原因。 我相信mapVertices方法会干扰count (一个是转换,一个是动作)。

解决方案将是

val lim = myGraph.vertices.count().toInt
val g2 = myGraph.mapVertices( ( id, name  ) => ( randomNumber(lim) ))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM