# Neo.ClientError.Procedure.ProcedureCallFailed with apoc.do.when

**URL:** <https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017>\
**Category:** Cypher\
**Created:** [January 24, 2020, 7:37pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017 "2020-01-24T19:37:51Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 24, 2020, 7:37pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/1 "2020-01-24T19:37:52Z")

</div>

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

I get following error

`Failed to invoke procedure `apoc.do.when`: Caused by: java.lang.ClassCastException: class org.neo4j.values.storable.NoValue cannot be cast to class org.neo4j.values.storable.BooleanValue (org.neo4j.values.storable.NoValue and org.neo4j.values.storable.BooleanValue are in unnamed module of loader 'app') (Failure when processing file '/spreadsheets/d/1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh/export?format=csv&id=1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh&gid=0' on line 2.)`

My Cypher Code:-

```auto
LOAD CSV WITH HEADERS FROM "google_drive_file_url" as row
MERGE(city:Cities {name:row.name})
WITH city, row
CALL apoc.do.when(row.region <> null,'OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Country) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(:Region { name: row.region})','OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Region) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(country: Country { name: row.country})', {city:city, row:row}) YIELD value
RETURN value

```

To check if my google\_driver\_file\_url has any problem i checked with

`LOAD CSV WITH HEADERS FROM "google_drive_file_url" as row RETURN row`  
it works, so could not understand the problem with my code... any help will be useful.

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [January 24, 2020, 9:24pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/2 "2020-01-24T21:24:59Z")

</div>

Does `logs/debug.log` contain a full stacktrace for this? If so, please paste it.

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 25, 2020, 6:12am UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/3 "2020-01-25T06:12:51Z")

</div>

Not found anything in logs/debug.log  
But found following at logs/query.log

```auto
2020-01-24 19:00:06.944+0000 ERROR id:1520 - 2940 ms: bolt-session	bolt	neo4j-javascript/0.0.0-dev client/127.0.0.1:5295	server/127.0.0.1:7687>	neo4j - neo4j - LOAD CSV WITH HEADERS FROM "https://docs.google.com/spreadsheets/d/1CzieQ74Gr3jEZ2SW-CC81dy-VxkGpgXpx2KdWAxuw3w/export?format=csv&id=1CzieQ74Gr3jEZ2SW-CC81dy-VxkGpgXpx2KdWAxuw3w&gid=0" as row
MERGE(city:Cities {name:row.name})
WITH city, row
CALL apoc.do.when(row.region <> null, 'OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Country) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(region: Region { name: row.region}) RETURN co', 'OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Region) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(country: Country { name: row.country}) RETURN co', {city:city, row:row}) YIELD value
RETURN value - {} - {type: 'user-direct', app: 'neo4j-browser_v4.0.2'} Failed to invoke procedure `apoc.do.when`: Caused by: java.lang.ClassCastException: class org.neo4j.values.storable.NoValue cannot be cast to class org.neo4j.values.storable.BooleanValue (org.neo4j.values.storable.NoValue and org.neo4j.values.storable.BooleanValue are in unnamed module of loader 'app') (Failure when processing file '/spreadsheets/d/1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh/export?format=csv&id=1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh&gid=0' on line 2.)
org.neo4j.exceptions.LoadCsvStatusWrapCypherException: Failed to invoke procedure `apoc.do.when`: Caused by: java.lang.ClassCastException: class org.neo4j.values.storable.NoValue cannot be cast to class org.neo4j.values.storable.BooleanValue (org.neo4j.values.storable.NoValue and org.neo4j.values.storable.BooleanValue are in unnamed module of loader 'app') (Failure when processing file '/spreadsheets/d/1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh/export?format=csv&id=1SDFsdfgsbvEZ2SW-SShdh23-XfjfjCHDHEkjm364646nvjfyryh&gid=0' on line 2.)
	at org.neo4j.cypher.internal.runtime.interpreted.pipes.LinenumberPipeDecorator$LinenumberIterator.wrapException(PipeDecorator.scala:117)
	at org.neo4j.cypher.internal.runtime.interpreted.pipes.LinenumberPipeDecorator$LinenumberIterator.hasNext(PipeDecorator.scala:94)
	at scala.collection.Iterator$$anon$10.hasNext(Iterator.scala:454)
	at org.neo4j.cypher.internal.runtime.interpreted.pipes.LinenumberPipeDecorator$LinenumberIterator.hasNext(PipeDecorator.scala:89)
	at org.neo4j.cypher.internal.runtime.interpreted.PipeExecutionResult.serveResults(PipeExecutionResult.scala:75)
	at org.neo4j.cypher.internal.runtime.interpreted.PipeExecutionResult.request(PipeExecutionResult.scala:63)
	at org.neo4j.cypher.internal.result.StandardInternalExecutionResult.request(StandardInternalExecutionResult.scala:88)
	at org.neo4j.cypher.internal.result.ClosingExecutionResult.request(ClosingExecutionResult.scala:135)
	at org.neo4j.bolt.runtime.AbstractCypherAdapterStream.handleRecords(AbstractCypherAdapterStream.java:105)
	at org.neo4j.bolt.v3.messaging.ResultHandler.onPullRecords(ResultHandler.java:41)
	at org.neo4j.bolt.v4.messaging.PullResultConsumer.consume(PullResultConsumer.java:42)
	at org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine$State.consumeResult(TransactionStateMachine.java:511)
	at org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine$State$1.streamResult(TransactionStateMachine.java:264)
	at org.neo4j.bolt.runtime.statemachine.impl.TransactionStateMachine.streamResult(TransactionStateMachine.java:92)
	at org.neo4j.bolt.v4.runtime.AutoCommitState.processStreamResultMessage(AutoCommitState.java:41)
	at org.neo4j.bolt.v4.runtime.AbstractStreamingState.processUnsafe(AbstractStreamingState.java:49)
	at org.neo4j.bolt.v3.runtime.FailSafeBoltStateMachineState.process(FailSafeBoltStateMachineState.java:48)
	at org.neo4j.bolt.runtime.statemachine.impl.AbstractBoltStateMachine.nextState(AbstractBoltStateMachine.java:143)
	at org.neo4j.bolt.runtime.statemachine.impl.AbstractBoltStateMachine.process(AbstractBoltStateMachine.java:91)
	at org.neo4j.bolt.messaging.BoltRequestMessageReader.lambda$doRead$1(BoltRequestMessageReader.java:90)
	at org.neo4j.bolt.runtime.DefaultBoltConnection.lambda$enqueue$0(DefaultBoltConnection.java:151)
	at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatchInternal(DefaultBoltConnection.java:240)
	at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:175)
	at org.neo4j.bolt.runtime.DefaultBoltConnection.processNextBatch(DefaultBoltConnection.java:165)
	at org.neo4j.bolt.runtime.scheduling.ExecutorBoltScheduler.executeBatch(ExecutorBoltScheduler.java:212)
	at org.neo4j.bolt.runtime.scheduling.ExecutorBoltScheduler.lambda$scheduleBatchOrHandleError$2(ExecutorBoltScheduler.java:195)
	at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.base/java.lang.Thread.run(Thread.java:834)

```

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [January 25, 2020, 8:23pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/4 "2020-01-25T20:23:10Z")

</div>

Can you please provide the first 5 lines of that csv file? With that I can try it on my end. The error message on its own does not yet enable to understand what's going on.

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 2:20pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/5 "2020-01-28T14:20:56Z")

</div>

Sorry for late reply sir... uploaded screenshot as could not upload the csv file

 ![Screenshot (879)](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/2X/e/e529ab51a5ebec6278e129f2ab0df4457f99116c.png)

Also to further explain my problem is not exactly apoc.do.when not running, i actually need it running as i want to utilize the If..Else options... i mean in my data  
If i have region as NULL i want to check if the name HAS\_REGION -\> if yes then delete and then create a HAS\_COUTRY with country And if region is NOT NULL then i want to check if the name HAS\_COUNTRY -\> if yes delete and the create a HAS\_REGION with the region.  
Culd not figure out the proper Cypher if...else code for that. FOREACH will not work as it has a conditional match code, UNWIND i could not figure out how to do... so thought apoc.do.when is the correct option

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [January 28, 2020, 4:03pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/6 "2020-01-28T16:03:32Z")

</div>

Not sure how empty fields are handled. One option would be to use `null`, the other an empty string. Have you considered that?

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 4:31pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/7 "2020-01-28T16:31:28Z")

</div>

> [@mithun.das](#):
>
> row.region \<\> null

this does not handle empty field?... so you want me to try putting "null" as a string in the csv and rewrite the condition as rw.region \<\> "null"

---

<div class="post-metadata">

**Author:** ![stefan.armbruster](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/stefan.armbruster/32/74_2.png) [@stefan.armbruster](https://community.neo4j.com/u/stefan.armbruster)\
**Post date:** [January 28, 2020, 5:52pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/8 "2020-01-28T17:52:19Z")

</div>

No. To validate just do

```auto
load csv with headers from .... as row
with row
where row.region is null
return row limit 5

```

Just to see if the filter works.

```auto
load csv with headers from .... as row
with row
where row.region = ''
return row limit 5

```

To see which value you get for an empty cell.

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 8:47pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/9 "2020-01-28T20:47:09Z")

</div>

Hi Yes i already do that

currently i use

`WITH row WHERE NOT row.region IS NULL`  
to load unempty regions  
and  
`WITH row WHERE row.region IS NULL`  
to load empty regions  
and both of them works respectively.  
It seems that in `apoc.do.when` the condition `row.region <> null` is not working.

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [January 28, 2020, 8:49pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/10 "2020-01-28T20:49:42Z")

</div>

Note that `<> null` is not the same as `IS NOT NULL`. You should not use equality and inequality (`=` or `<>`) for null tests, as the result will always be null.

You should be using IS NULL or IS NOT NULL for null tests.

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 8:55pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/11 "2020-01-28T20:55:40Z")

</div>

Ok so in the

> [@mithun.das](#):
>
> My Cypher Code:-
> 
> ```auto
> LOAD CSV WITH HEADERS FROM "google_drive_file_url" as row
> MERGE(city:Cities {name:row.name})
> WITH city, row
> CALL apoc.do.when(row.region <> null,'OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Country) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(:Region { name: row.region})','OPTIONAL MATCH (city)-[rel:CITY_OF]->(:Region) DETACH DELETE rel MERGE (city)-[co:CITY_OF]->(country: Country { name: row.country})', {city:city, row:row}) YIELD value
> RETURN value
> 
> ```

So here instead of using `row.region <> null` i must use `IS NOT NULL` right @andrew_bowman ?

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [January 28, 2020, 8:57pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/12 "2020-01-28T20:57:34Z")

</div>

> So here instead of using `row.region <> null` i must use `IS NOT NULL` right @andrew.bowman ?

Yes, exactly.

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 8:59pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/13 "2020-01-28T20:59:18Z")

</div>

Thank you i will try this and mark your answer as a solution on 2mrw. Thanks for the help guys 🙂

---

<div class="post-metadata">

**Author:** ![mithun.das](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mithun.das/32/8732_2.png) [@mithun.das](https://community.neo4j.com/u/mithun.das)\
**Post date:** [January 28, 2020, 9:05pm UTC](https://community.neo4j.com/t/neo-clienterror-procedure-procedurecallfailed-with-apoc-do-when/14017/14 "2020-01-28T21:05:57Z")

</div>

@andrew_bowman Just now tried... and it worked awesome 😃
