Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-17-2019 08:31 AM
Hello,
I've tried using the apoc.path.expandConfig to find a path.
I've called it twice with different sequence and if the second one didn't find any path, it "deleted" the result of the first apoc.
For example - The graph
CREATE (n:Person:TrailStart)-[:FRIEND_OF]->(:Person)-[:FRIEND_OF]->(:Person)-[:FRIEND_OF]->(:Person:TrailEnd)
The queries -
This one returned the path as expected
MATCH (end_node:TrailEnd)
WITH collect(end_node) as end_nodes
MATCH (start_node:TrailStart)
CALL apoc.path.expandConfig(start_node, {
endNodes: end_nodes,
sequence: '+person, FRIEND_OF>'
}) YIELD path as path1
RETURN path1
This one return nothing
MATCH (end_node:TrailEnd)
WITH collect(end_node) as end_nodes
MATCH (start_node:TrailStart)
CALL apoc.path.expandConfig(start_node, {
endNodes: end_nodes,
sequence: '+person, FRIEND_OF>'
}) YIELD path as path1
CALL apoc.path.expandConfig(start_node, {
endNodes: end_nodes,
sequence: '+person, NOT_FRIEND_OF>'
}) YIELD path as path2
RETURN path1
If the second apoc procedure did find something, the result of the first procedure wasn't deleted.
Thank you,
Michael
03-17-2019 05:33 PM
Not really sure what you expect.
The first procedure call creates rows and for each of those rows the second procedure is called.
And the result is the combined product of both.
if the first doesn't find anything you will get no rows returned
03-18-2019 12:16 AM
Oh I see, its like two matches.
So how can I add the two results of the procedures? like if the first found a trail, and the second didnt find any trail, how can I continue the query with the trail found in the first procedure? (trail + null)
Thank you,
Michael
03-18-2019 07:46 AM
You can use the optional
config parameter when making the call which will keep the row even if no results are found (you'll get a null
for path
).
Secondly, you would want to collect the results of the first call before calling the second, so the second would only be called once total rather than once per every row yielded by the first call.
Then you can collect and combine the collections, similar to one of the approaches in this kb article on post-UNION processing.
All the sessions of the conference are now available online