From a322c451266d3d9d03b234d46b28439fef25045a Mon Sep 17 00:00:00 2001 From: Anqi Date: Wed, 16 Nov 2022 14:04:30 +0800 Subject: [PATCH 1/2] fix npe for setting directed flag --- .../nebula/algorithm/lib/Node2vecAlgo.scala | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala b/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala index 98e777a..989467b 100644 --- a/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala +++ b/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala @@ -155,11 +155,14 @@ object Node2vecAlgo { graph = Graph(indexedNodes, indexedEdges) .mapVertices[NodeAttr] { case (vertexId, clickNode) => - val (j, q) = this.setupAlias(clickNode.neighbors) - val nextNodeIndex = this.drawAlias(j, q) - clickNode.path = Array(vertexId, clickNode.neighbors(nextNodeIndex)._1) - - clickNode + if (clickNode != null) { + val (j, q) = this.setupAlias(clickNode.neighbors) + val nextNodeIndex = this.drawAlias(j, q) + clickNode.path = Array(vertexId, clickNode.neighbors(nextNodeIndex)._1) + clickNode + } else { + NodeAttr() + } } .mapTriplets { edgeTriplet: EdgeTriplet[NodeAttr, EdgeAttr] => val (j, q) = this.setupEdgeAlias(bcP.value, bcQ.value)(edgeTriplet.srcId, @@ -210,11 +213,14 @@ object Node2vecAlgo { .map { case (edge, ((srcNodeId, pathBuffer), attr)) => try { - val nextNodeIndex = this.drawAlias(attr.J, attr.q) - val nextNodeId = attr.dstNeighbors(nextNodeIndex) - pathBuffer.append(nextNodeId) - - (srcNodeId, pathBuffer) + if (pathBuffer != null && pathBuffer.nonEmpty && attr.dstNeighbors != null && attr.dstNeighbors.nonEmpty) { + val nextNodeIndex = this.drawAlias(attr.J, attr.q) + val nextNodeId = attr.dstNeighbors(nextNodeIndex) + pathBuffer.append(nextNodeId) + (srcNodeId, pathBuffer) + } else { + pathBuffer + } } catch { case e: Exception => throw new RuntimeException(e.getMessage) } From 358fea7aaa9c3440f0c354d8bdeb68597ea1a7bf Mon Sep 17 00:00:00 2001 From: Anqi Date: Thu, 5 Jan 2023 10:21:47 +0800 Subject: [PATCH 2/2] fix data struct --- .../scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala b/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala index 989467b..36356c4 100644 --- a/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala +++ b/nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala @@ -219,7 +219,7 @@ object Node2vecAlgo { pathBuffer.append(nextNodeId) (srcNodeId, pathBuffer) } else { - pathBuffer + (srcNodeId, pathBuffer) } } catch { case e: Exception => throw new RuntimeException(e.getMessage)