【问题标题】:Spark Graphx : class not found error on EMR clusterSpark Graphx:在 EMR 集群上找不到类错误
【发布时间】:2018-09-01 04:49:24
【问题描述】:

我正在尝试使用 Grapghx Pregel 处理分层数据,并且我的代码在本地运行良好。

但是当我在我的 Amazon EMR 集群上运行时,它给了我一个错误:

java.lang.NoClassDefFoundError: Could not initialize class

发生这种情况的原因是什么?我知道该类在 jar 文件中,因为它在我的本地运行良好,也没有构建错误。

我已经包含了 GraphX 对 pom 文件的依赖。

这是抛出错误的代码的 sn-p:

def calcTopLevelHierarcy (vertexDF: DataFrame, edgeDF: DataFrame): RDD[(Any, (Int, Any, String, Int, Int))]  =
 {

  val verticesRDD = vertexDF.rdd
                  .map { x => (x.get(0), x.get(1), x.get(2)) }
                  .map { x => (MurmurHash3.stringHash(x._1.toString).toLong, (x._1.asInstanceOf[Any], x._2.asInstanceOf[Any], x._3.asInstanceOf[String])) }

//create the edge RD top down relationship
  val EdgesRDD =  edgeDF.rdd.map { x => (x.get(0), x.get(1)) }
                 .map { x => Edge(MurmurHash3.stringHash(x._1.toString).toLong, MurmurHash3.stringHash(x._2.toString).toLong, "topdown") }

// create the edge RD top down relationship
 val graph = Graph(verticesRDD, EdgesRDD).cache()
  //val pathSeperator = """/"""

//initialize id,level,root,path,iscyclic, isleaf
  val initialMsg = (0L, 0, 0.asInstanceOf[Any], List("dummy"), 0, 1)
  val initialGraph = graph.mapVertices((id, v) => (id, 0, v._2, List(v._3), 0, v._3, 1, v._1))
  val hrchyRDD = initialGraph.pregel(initialMsg, Int.MaxValue, EdgeDirection.Out)(setMsg, sendMsg, mergeMsg)
//build the path from the list
  val hrchyOutRDD = hrchyRDD.vertices.map { case (id, v) => (v._8, (v._2, v._3, pathSeperator + v._4.reverse.mkString(pathSeperator), v._5, v._7)) }
  hrchyOutRDD
}

我能够缩小导致错误的范围:

val hrchyRDD = initialGraph.pregel(initialMsg, Int.MaxValue, EdgeDirection.Out)(setMsg, sendMsg, mergeMsg)

【问题讨论】:

  • 如何启动它?
  • @XavierGuihot 你的意思是我如何在集群上提交我的工作?我使用 spark submit 将其添加为步骤。

标签: scala apache-spark rdd spark-graphx


【解决方案1】:

我遇到了同样的问题,当从 spark-submit 执行时,我能够在 spark-shell 失败的情况下运行它。这是我试图执行的代码的example(看起来和你的一样)

指出我找到正确解决方案的错误是:

org.apache.spark.SparkException: A master URL must be set in your configuration

在我的例子中,我遇到了这个错误,因为我在主函数之外定义了 SparkContext:

object Test {        
     val sc = SparkContext.getOrCreate
     val sqlContext = new SQLContext(sc)
     def main(args: Array[String]) {
                 ...
     }
}

我可以通过将主函数中的 SparkContext 和 sqlContext 移动为 described in this other post 来解决它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-17
    • 1970-01-01
    相关资源
    最近更新 更多