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.

How to call a yield statement within apoc.iterate?

ldj20
Node Link

I'm wondering if it's possible to include something like apoc.create.setProperty or apoc.refactor.invert inside an iterate statement. Something like:

CALL apoc.periodic.iterate("MATCH ()-[rel:RELATED]->() RETURN rel", 
"CALL apoc.refactor.invert(rel) YIELD input, output RETURN input, output",
{batchSize:1000, parallel: true})
YIELD batches, total RETURN batches, total

Yield doesn't mesh well with the way iterate works so I can't think of a way to make this work. Anyone have any thoughts?

1 REPLY 1

Sure, you just have to yield one of the result columns and return a count(*) to make it a valid statement.

changing rels in parallel might get you a lot of locking esp. before 4.3

CALL apoc.periodic.iterate("MATCH ()-[rel:RELATED]->() RETURN id(rel) as id", 
"MATCH ()-[rel:RELATED]->() WHERE id(rel) = id WITH * 
 CALL apoc.refactor.invert(rel) YIELD output RETURN count(*)",
{batchSize:1000, parallel: true})
YIELD batches, total RETURN batches, total