GraphX无法正常工作Spark / Scala

时间:2016-12-19 01:42:49

标签: scala apache-spark spark-graphx

我正在尝试在apache Spark / Scala中创建一个GraphX对象,但由于某些原因它似乎不起作用。我附上了一个示例输入文件的文件,实际的程序代码是:

package SGraph

import org.apache.spark._

import org.apache.spark.SparkContext._

import org.apache.spark.sql._

import org.apache.log4j._

import org.apache.spark.rdd.RDD

import org.apache.spark.graphx._
`
    object GooglePlusGraph {

  /** Our main function where the action happens */
      def main(args: Array[String]) {

    // Set the log level to only print errors
    Logger.getLogger("org").setLevel(Level.ERROR)

    // Create a SparkContext using every core of the local machine
    val sc = new SparkContext("local[*]", "GooglePlusGraphX") 

    val lines = sc.textFile("../Example.txt")

    val ratings = lines.map(x => x.toString().split(":")(0))

    val verts  = ratings.map(line => (line.toLong,line)) 

    val edges = lines.flatMap(makeEdges)  

    val default = "Nobody"
    val graph = Graph(verts, edges, default).cache()

    graph.degrees.join(verts).take(10).foreach(println)
    }

    def makeEdges(line: String) : List[Edge[Int]] = {

    import scala.collection.mutable.ListBuffer

    var edges = new ListBuffer[Edge[Int]]()

    val fields = line.split(",").flatMap(a => a.split(":"))

    val origin = fields(0)

    for (x <- 1 to (fields.length - 1)) {
      // Our attribute field is unused, but in other graphs could
      // be used to deep track of physical distances etc.
      edges += Edge(origin.toLong, fields(x).toLong, 0)
    }

    return edges.toList
  }
}

我得到的第一个错误如下:

16/12/19 01:28:33 ERROR Executor: Exception in task 0.0 in stage 2.0 (TID 3)
java.lang.NumberFormatException: For input string: "935750800736168978117"

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

以下问题与您的问题相同。

Cannot convert string to a long in scala

指定的数字超出Long(19位)的最大位数后的21位数。