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

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:-

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.

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

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

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)

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.

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

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

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

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"

No. To validate just do

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.

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.

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.

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.

Ok so in the

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

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

Yes, exactly.

1 Like

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

@andrew_bowman Just now tried... and it worked awesome :smiley:

1 Like