У меня есть код для анализа графа, чтобы найти все пути заданной начальной вершины. Я получаю NPE, когда пытаюсь найти ребра по dest vertex. Вот полный код: https://github.com/ssemichael/spark-play/blob/master/src/main/scala/org/heng/spark/graph/FindPath.scala
вот метод ипроблемная строка находится на // найти соседей
def findPath(graph: Graph[Long, String], result: Array[Path], currentLevel: RDD[Path]): Array[Path] = {
if (currentLevel.isEmpty()) {
return result
}
//find neighbors
val neighbors = currentLevel.map(t => PathForFilter(t.src, graph.collectEdges(EdgeDirection.Out).lookup(t.dest), t.path))
//if no more neighbors, put paths to result
val collected = neighbors.filter(t => t.dest.length == 0).map(t => Path(t.src, t.path.last, t.path))
val newResult = result ++ collected.collect()
//otherwise, find next level neighbors
val nextLevel = neighbors.filter(t => t.dest.length > 0 && !t.path.contains(t.dest(0)(0).dstId) ).map(
t => Path(t.src, t.dest(0)(0).dstId, t.path :+ t.dest(0)(0).dstId))
findPath(graph, newResult, nextLevel)
}
это трассировка стека
ERROR 2019-10-28 14:57:29,409 2478 org.apache.spark.executor.Executor [Executor task launch worker for task 24] Exception in task 3.0 in stage 8.0 (TID 24)
java.lang.NullPointerException
at org.apache.spark.graphx.impl.GraphImpl.aggregateMessagesWithActiveSet(GraphImpl.scala:194)
at org.apache.spark.graphx.Graph.aggregateMessages(Graph.scala:378)
at org.apache.spark.graphx.GraphOps.collectEdges(GraphOps.scala:178)
at org.heng.spark.graph.FindPath$$anonfun$1.apply(FindPath.scala:28)
at org.heng.spark.graph.FindPath$$anonfun$1.apply(FindPath.scala:28)
at scala.collection.Iterator$$anon$11.next(Iterator.scala:410)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:463)
at scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:409)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:59)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:104)
at scala.collection.mutable.ArrayBuffer.$plus$plus$eq(ArrayBuffer.scala:48)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:310)
at scala.collection.AbstractIterator.to(Iterator.scala:1334)
at scala.collection.TraversableOnce$class.toBuffer(TraversableOnce.scala:302)
at scala.collection.AbstractIterator.toBuffer(Iterator.scala:1334)
at scala.collection.TraversableOnce$class.toArray(TraversableOnce.scala:289)
at scala.collection.AbstractIterator.toArray(Iterator.scala:1334)
at org.apache.spark.rdd.RDD$$anonfun$collect$1$$anonfun$13.apply(RDD.scala:945)
at org.apache.spark.rdd.RDD$$anonfun$collect$1$$anonfun$13.apply(RDD.scala:945)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:2101)
at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:2101)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:90)
at org.apache.spark.scheduler.Task.run(Task.scala:121)
at org.apache.spark.executor.Executor$TaskRunner$$anonfun$10.apply(Executor.scala:408)
at org.apache.spark.util.Utils$.tryWithSafeFinally(Utils.scala:1360)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:414)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)