Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-06-2021 04:13 AM
Question: How to access Node/ Node properties within multiple nested apoc.periodic.iterator (s) ?
to create sample data:
:params eventParam=> [{eid: "e1"},{eid: "e2"}];
Query:
call apoc.periodic.iterate(
'
// create some nodes - *ideally these nodes will be read from some jdbc source*
UNWIND [1, 2, 3] AS gid
MERGE (f:FromNode {gid: gid} ) return f
',
'
// Run a nested apo.periodic.iterator - procedure to create relationship (FromNode)-[Related]->(Event) - 1 to n relationship
call apoc.periodic.iterate(
" unwind $events as ev return ev " , // *ideally events will be derived from (f)'s property
" merge (f)-[:RELATED_TO]->(e:Event {eid:ev.eid} ) return e ",
{params:{events: $events}}
) yield batches return batches
// Note there may be more iterators inside
//call apoc.periodic.iterate(
// " unwind $alerts as alert return alert " ,
// " merge (f)-[:HAS]->(a:Alert{..} ) return a ",
// {params:{alerts: $alerts}}
// ) yield batches return batches
',
{params:{events:$eventParam}, parallel:true}
)
Actual Output:
Expected Output:
Issue is: FromNode created in first cypherIterator is not accessible in nested iterator while creating relationship
08-19-2021 11:48 PM
you also need to pass "f" as parameter like you do with events
also best to use id(f) and look up the node/relationship again, as otherwise there might be issues where the tx data of the inner transactions is stored in the main tx.
Also I don't think you need multiple periodic iterates, just use one and move the unwind of the events into the update statement and reduce the batch size.
you should also merge the event in an extra clause otherwise you get one event node per FromNode
All the sessions of the conference are now available online