neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            

Home Page:https://neo4j.com/labs/apoc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

is there any apoc procedure can make allShortestPaths execute in parallel?

Reid00 opened this issue · comments

neo4j version: 5.7

I have five pairs (A, B), (A,C), (A,D), (B,C), (B,D),I want to get the allShortestPaths with below statement:

format!("MATCH (start:{}{{keyNo: $start}})  OPTIONAL MATCH (end:{}{{keyNo:$end}}),
                    p = allShortestPaths ((start)-[:INVEST|LEGAL|EMPLOY|BRANCH|HISINVEST|HISLEGAL|HISEMPLOY*..{}]-(end))
                    RETURN p LIMIT 15", start_label, end_label, hop);

The driver is HTTP API: https://neo4j.com/docs/http-api/current/transactions/ , use it execute multiple queries.

but HTTP API run multiple queries in sequence, it will be slow. So I want to know is there any apoc can wrapper the query make it execute in parallel.

I try to apoc.periodic.iterate, apoc.cypher.runManyReadOnly, it's both no path return, want to use apoc.cypher.runParallel but I have no idea how to use it?

in this case it won't help you for intra-query-parallelism. Best wait for the new concurrent execution that will be coming soon.

you can also parallelize the execution from python

if you want to use intra-query parallelism, you need to have larger lists of starting nodes that you would then parallelize over.

https://neo4j.com/labs/apoc/4.3/overview/apoc.cypher/apoc.cypher.mapParallel2/

something like

MATCH (start:Start{{keyNo: $start}})  
OPTIONAL MATCH (end:End)
WITH start, collect(end) as list

call apoc.cypher.mapParallel2(
// fragment
'MATCH p = allShortestPaths ((start)-[:INVEST|LEGAL|EMPLOY|BRANCH|HISINVEST|HISLEGAL|HISEMPLOY*..10]-(_)) RETURN p LIMIT 15', 
// list of nodes to parallelize over, in statement it uses _ for those
list, 
// parameters that are passed in
{start:start}) yield value
return value.p as p

Thank you very much @jexp.
In my cases, I have 55 (start, end) pairs at most. I list part of them, it will be search from diff labels, like below I try to use apoc.cypher.runParallel (it's syntax error in fact).
Could you please give some advice how to refactor my cpyher?

MATCH (n:Person) where n.keyNo IN ["p501f298f6fc918f1c1e0fb94268f53b", "p756de5fbd0f8acc034a55cd43c97821",
"p5baf3e85f5b3e69e5b47871813d0bfb", "pr45eadf7927a52ca7d6a96a1216794e"]
WITH collect(n) as starts
MATCH (m:Company) where m.keyNo IN ["8c9f7ddc1a7bcee3d1f7676773fe9404", "f9caa5f860e1c9faf7867c301b6b6a06", 
"0bf44c895427b4e60801aa4150b908a8", "dd67092006c584c069b36944bbb6043f", "1ac04be0065f9740d1647cade5790adc",
"f5dbba14219585b4578bb63040a3d418"]
WITH  starts, collect(m) as ends
WITH starts + ends AS nodes
UNWIND nodes as n
UNWIND nodes as m
WITH n,m WHERE id(n) < id(m)
MATCH path = allShortestPaths( (n)-[:INVEST|LEGAL|EMPLOY|BRANCH|HISINVEST|HISLEGAL|HISEMPLOY*..15]-(m) )
CALL apoc.cypher.parallel('RETURN path', {}, 'm,n')
YIELD value RETURN value.title as title

Just wait a week and then try the prefix cypher runtime=parallel with regular Neo4j.

thank you @jexp. You mean cypher runtime=parallel is new feature for the latest neo4j version? is there any docs currently?

hello guys, is there any update? where i can find some docs?

Got it, thanks

Closing this issues as handled by parallel runtime.