Skip to content

Commit 0e0668e

Browse files
authored
fix npe for setting directed flag (#58)
* fix npe for setting directed flag * fix data struct
1 parent 78713c1 commit 0e0668e

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

nebula-algorithm/src/main/scala/com/vesoft/nebula/algorithm/lib/Node2vecAlgo.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ object Node2vecAlgo {
155155
graph = Graph(indexedNodes, indexedEdges)
156156
.mapVertices[NodeAttr] {
157157
case (vertexId, clickNode) =>
158-
val (j, q) = this.setupAlias(clickNode.neighbors)
159-
val nextNodeIndex = this.drawAlias(j, q)
160-
clickNode.path = Array(vertexId, clickNode.neighbors(nextNodeIndex)._1)
161-
162-
clickNode
158+
if (clickNode != null) {
159+
val (j, q) = this.setupAlias(clickNode.neighbors)
160+
val nextNodeIndex = this.drawAlias(j, q)
161+
clickNode.path = Array(vertexId, clickNode.neighbors(nextNodeIndex)._1)
162+
clickNode
163+
} else {
164+
NodeAttr()
165+
}
163166
}
164167
.mapTriplets { edgeTriplet: EdgeTriplet[NodeAttr, EdgeAttr] =>
165168
val (j, q) = this.setupEdgeAlias(bcP.value, bcQ.value)(edgeTriplet.srcId,
@@ -210,11 +213,14 @@ object Node2vecAlgo {
210213
.map {
211214
case (edge, ((srcNodeId, pathBuffer), attr)) =>
212215
try {
213-
val nextNodeIndex = this.drawAlias(attr.J, attr.q)
214-
val nextNodeId = attr.dstNeighbors(nextNodeIndex)
215-
pathBuffer.append(nextNodeId)
216-
217-
(srcNodeId, pathBuffer)
216+
if (pathBuffer != null && pathBuffer.nonEmpty && attr.dstNeighbors != null && attr.dstNeighbors.nonEmpty) {
217+
val nextNodeIndex = this.drawAlias(attr.J, attr.q)
218+
val nextNodeId = attr.dstNeighbors(nextNodeIndex)
219+
pathBuffer.append(nextNodeId)
220+
(srcNodeId, pathBuffer)
221+
} else {
222+
(srcNodeId, pathBuffer)
223+
}
218224
} catch {
219225
case e: Exception => throw new RuntimeException(e.getMessage)
220226
}

0 commit comments

Comments
 (0)