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 execute apoc.do.case procedure in parallel?

magaton
Node Link

My command lookslike this:

MATCH (c:Client) 
WITH collect(c) AS clients
CALL apoc.cypher.mapParallel2('
    CALL apoc.do.case([
      _.type="Plain", "SET _.state=1",
      _.type="Super", "SET _.state=2"
     ],"SET _.state=0", 
      {}) 
    YIELD value
    RETURN value',
    {}, clients, 😎 YIELD value 
   RETURN value.client.login as login, value.client.state as state

And I am getting:

Failed to invoke procedure `apoc.cypher.mapParallel2`: Caused by: org.neo4j.graphdb.NotInTransactionException: This transaction has already been closed.

Also, how should I escape quotes in case state is STRING

1 ACCEPTED SOLUTION

CALL apoc.periodic.iterate(
  "match (c:Client) return c",
  'CALL apoc.do.case([
      c.type="Plain", "SET c.state=\'foo\'",
      c.type="Super", "SET c.state=\'bar\'"
     ],"SET c.state=\'baz\'", 
      {c: c}) 
    YIELD value
    RETURN value',
    {}
);

View solution in original post

3 REPLIES 3

If you want to update properties I would rather use apoc.periodic.iterate, as shown below:

CALL apoc.periodic.iterate(
  "match (c:Client) return c",
  'CALL apoc.do.case([
      c.type="Plain", "SET c.state=5",
      c.type="Super", "SET c.state=6"
     ],"SET c.state=0", 
      {c: c}) 
    YIELD value
    RETURN value',
    {}
);

Thanks, I have done the same in the meantime. Now I hit another problem:
What if the state is String? How should I escape the quotes?
Please note that my apoc.do.case is a monster in the real use case, lots of sets as a result of complex calculation.

CALL apoc.periodic.iterate(
  "match (c:Client) return c",
  'CALL apoc.do.case([
      c.type="Plain", "SET c.state=\'foo\'",
      c.type="Super", "SET c.state=\'bar\'"
     ],"SET c.state=\'baz\'", 
      {c: c}) 
    YIELD value
    RETURN value',
    {}
);