本文介绍了星火斯卡拉GraphX​​:映射函数中调用最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的code映射调用在全球图形变量最短路径函数时,在那里我recieving一个空指针异常运行时错误的问题。出于某种原因,即使在终端初始化距离定期抛出任何错误,并调用testF()正常工作,以及,它得到映射,当它不工作。当我删除testF函数内eroneous长途电话,该示例正常工作。有谁知道为什么发生这种情况?

  VAL testG = Graph.fromEdges [INT,INT](sc.parallelize(名单(边缘(1,2,1),边(2,3,1))) 0)
VAL testRDD = sc.parallelize(列表(1,2,3,4))
高清testF():INT = {
     VAL距离= ShortestPaths.run(testG,SEQ(15134567L))
     返回5
}
testF()//工作正常,并返回5
VAL testR = {testRDD.map的情况下(NUM)=> (NUM,测试())}
testR.take(10).foreach(的println)//给出一个空指针错误


解决方案

至于@DanieldePaula提到的 - 你不能巢内RDD的分布式方法。相反,在逻辑的 ShortestPaths.run 将需要提取并重新直斯卡拉code - 不会的SC SparkContext )的方法, SparkJob ,或任何其他驱动机制只。你需要坚持使用序列化和工人兼容的逻辑。

I'm having an issue in my code where I'm recieving a null pointer exception runtime error when mapping a function that calls shortest path on a global graph variable. For some reason, even though initializing distance in the terminal regularly throws no error, and calling testF() normally works as well, it doesn't work when its getting mapped. When i remove the eroneous distance call inside the testF function, the example works fine. Does anyone know why this is happening?

val testG = Graph.fromEdges[Int, Int](sc.parallelize(List(Edge(1, 2, 1), Edge(2, 3, 1))), 0)
val testRDD = sc.parallelize(List(1, 2, 3, 4))
def testF() : Int = {
     val distances = ShortestPaths.run(testG, Seq(15134567L))
     return 5
}
testF() //works fine and returns 5
val testR = testRDD.map{case(num) => (num, test())}
testR.take(10).foreach(println) //gives a null pointer error
解决方案

As @DanieldePaula alluded to - you can not nest the distributed methods within the RDD's. Instead the logic within the ShortestPaths.run would need to be extracted and reformulated as straight scala code - and without any mention of sc (SparkContext) methods, SparkJob, or any other Driver-only mechanisms. You need to stick with serializable and Worker-compatible logic.

这篇关于星火斯卡拉GraphX​​:映射函数中调用最短路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 21:52