cancel
Showing results for 
Search instead for 
Did you mean: 

GDS Dijkstra ShortestPath returns empty for multiple queries even though some paths have been return

cuneyttyler
Node Clone
I'm making multiple calls to GDS Dijkstra in one query: Below first call returns a path as path1 and second call returns nothing. When I make these queries together, whole query returns nothing. What might be the reason of that? Must I do separate calls rather?

 

 

CALL gds.shortestPath.dijkstra.stream('entityGraph', {sourceNode: 4638405,targetNode: 998302}) YIELD path as path1
CALL gds.shortestPath.dijkstra.stream('entityGraph', {sourceNode: 4638405,targetNode: 2098491}) YIELD path as path2
WITH collect(path1) + collect(path2) as all RETURN all

 

 

 

1 ACCEPTED SOLUTION

glilienfield
Ninja
Ninja

The results of the second call get appended to the first’s results. If the second call has zero results, then nothing will be returned.  
Use a call subquery to call them in a ‘union’ clause.

View solution in original post

5 REPLIES 5

glilienfield
Ninja
Ninja

The results of the second call get appended to the first’s results. If the second call has zero results, then nothing will be returned.  
Use a call subquery to call them in a ‘union’ clause.

I did this :

CALL {
   CALL gds.shortestPath.dijkstra.stream('entityGraph', {sourceNode: 4638405,targetNode: 2098491}) YIELD path 
UNION
   CALL gds.shortestPath.dijkstra.stream('entityGraph', {sourceNode: 4638405,targetNode: 998302}) YIELD path 
} return path

Now it says 'Unknown variable path@2' 

Okay, I needed to add RETURN to end of each query.

I have a similar issue and so far I found no explanation why appending 'nothing' to 'something' returns nothing instead of something?

glilienfield
Ninja
Ninja

I guess you can consider it like a sql inner join when you have a collection of matches. The all have to return results and they are mixed together. The optional match is like a sql outer join; it will return 'null' for its result and the results are mixed together. 

https://neo4j.com/docs/cypher-manual/current/clauses/optional-match/