cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Nested apoc.periodic.iterate - error

slygren
Node Clone

Referring my question from earlier today (' When simplest operation turns difficult') - is there a reason why nested apoc.periodic.iterate calls fails? Any obvious errors with my code here, or is the threading of iterate disallowing any such use cases?

unwind [{tag:'123', c:[{e:1}]},{tag:'234', c:[{e:2},{e:3}]},{tag:'345',c:[{e:5}]},{tag:'456',c:[{e:4},{e:6}]}] as event
with collect(event) as events
CALL apoc.periodic.iterate("unwind $events as event return event", 
"merge (p:TST {uuid:apoc.create.uuid()}) set p.tag=event.tag with p, event match (h:P) where h.n='n' merge (h)-[:RELATES_TO]->(p) with p, event, h optional match (h)-[:RELATES_TO]->(p_last:TST) where p_last.last=TRUE foreach(_ in case when exists(p_last.last) THEN [1] ELSE [] END | set p_last.last=FALSE merge (p_last)-[:NEXT]->(p)) set p.last=TRUE with p, event call apoc.periodic.iterate('unwind $event.c as s return s, $p as p','merge (c:Child uuid:apoc.create.uuid()) on create set c.e=s.e merge (p)-[:HAS_CHILD]->(c) optional match (p)-[:HAS_CHILD]->(c_last:Child) where c_last.last=TRUE foreach(ignoreMe in case when exists(c_last.last) THEN [1] ELSE [] END | set c_last.last=FALSE merge (c_last)-[:NEXT]->(c)) set c.last=TRUE', {batchSize:1, parallel:false, params:{event:event, p:p}}) YIELD batches, total, errorMessages return 0", {batchSize:1, parallel:false, params:{events:events}}) YIELD batches, total, errorMessages 
return 0
3 REPLIES 3

Can you provide how it fails, the error messages would be helpful, as well as whatever is returned from errorMessages (instead of return 0).

Also the UNWIND and collect() aren't necessary on lines 2 and 3. Just use WITH <your collection of stuff> as events then pass that into your iterate() call.

There's no errors reported, only process seems to be hanging forever. Here's the neo4j.log INFO messages appearing. Nothing else to be found in debug.log either.

2019-10-22 21:16:36.565+0000 INFO  starting batching from `unwind $events as event return event` operation using iteration `merge (p:TST {uuid:apoc.create.uuid()}) set p.tag=event.tag with p, event match (h:P) where h.n='n' merge (h)-[:RELATES_TO]->(p) with p, event, h optional match (h)-[:RELATES_TO]->(p_last:TST) where p_last.last=TRUE foreach(_ in case when exists(p_last.last) THEN [1] ELSE [] END | set p_last.last=FALSE merge (p_last)-[:NEXT]->(p)) set p.last=TRUE with p, event call apoc.periodic.iterate('unwind $event.c as s return s','merge (c:Child {uuid:apoc.create.uuid()}) on create set c.e=s.e with $p as p, c merge (p)-[:HAS_CHILD]->(c) with p, c optional match (p)-[:HAS_CHILD]->(c_last:Child) where c_last.last=TRUE foreach(ignoreMe in case when exists(c_last.last) THEN [1] ELSE [] END | set c_last.last=FALSE merge (c_last)-[:NEXT]->(c)) set c.last=TRUE', {batchSize:1, parallel:false, params:{event:event, p:p}}) YIELD batches, total, errorMessages return errorMessages` in separate thread
2019-10-22 21:16:37.338+0000 INFO  starting batching from `unwind $event.c as s return s` operation using iteration `merge (c:Child {uuid:apoc.create.uuid()}) on create set c.e=s.e with $p as p, c merge (p)-[:HAS_CHILD]->(c) with p, c optional match (p)-[:HAS_CHILD]->(c_last:Child) where c_last.last=TRUE foreach(ignoreMe in case when exists(c_last.last) THEN [1] ELSE [] END | set c_last.last=FALSE merge (c_last)-[:NEXT]->(c)) set c.last=TRUE` in separate thread

As for the UNWIND and collect() part - it's just there to act as how the Kafka connect Neo4j sink pushes batches off of a topic to Neo. And last, the 'outer' apoc.periodic.iterate works as intended, only while adding the inner one it stops.

slygren
Node Clone

Anyone have any idea?