neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
https://neo4j.com/labs/apoc
Apache License 2.0
1.71k stars 493 forks source link

multiple apoc.do.when not working #1394

Closed mithundas79 closed 4 years ago

mithundas79 commented 4 years ago

Neo4j version 4.0.0 Enterprise Neo4j Desktop 1.2.4 Neo4j Browser version: 4.0.2

My code is following

LOAD CSV WITH HEADERS FROM "MY-CSV-FILE-LINK" as r
WITH r
MATCH (country:Country { key: "country-1"})
unwind r as row
with row, country
CALL apoc.do.when(
   row.search_visibility = 'TRUE',
   'REMOVE country:UNSEARCHABLE
   SET country:SEARCHABLE',
   'REMOVE country:SEARCHABLE
   SET country:UNSEARCHABLE', { row: row, country: country}) YIELD value
unwind row as rowList
WITH value as ignored, rowList, country
CALL apoc.do.when(
   rowList.list_visibility = 'TRUE',
   'REMOVE country:INVISIBLE
   SET country:VISIBLE',
   'REMOVE country:VISIBLE
   SET country:INVISIBLE', { row: rowList, country: country}) YIELD value
WITH value as ignored
RETURN ignored

The first apoc.do.when is running but last one is NOT running.... i interchanged the queries to test, saw same case. Thats why thought it can be an issue hence reported here. Sorry if have mistaken something. This also happens with apoc.do.case

mithundas79 commented 4 years ago

I found the solution.. and sorry to report it as bug.... The solution is... as i am doing write queries, i have to return something from my queries... as i was not returning thats why my first query ran but second did not... posting the solution...

LOAD CSV WITH HEADERS FROM "MY-CSV-FILE-LINK" as row
WITH row
MATCH (country:Country { key: "country-1"})
WITH row, country
CALL apoc.do.when(
   row.search_visibility = 'TRUE',
   'REMOVE country:UNSEARCHABLE
   SET country:SEARCHABLE RETURN country',
   'REMOVE country:SEARCHABLE
   SET country:UNSEARCHABLE RETURN country', { row: row, country: country}) YIELD value
WITH value as ignored, row, country
CALL apoc.do.when(
   row.list_visibility = 'TRUE',
   'REMOVE country:INVISIBLE
   SET country:VISIBLE RETURN country',
   'REMOVE country:VISIBLE
   SET country:INVISIBLE RETURN country', { row: row, country: country}) YIELD value
WITH value as ignored
RETURN ignored