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

Cypher file generated by apoc.export.cypher.all causes "Failed to evaluate expression" error in cypher-shell #1728

Closed PoshAlpaca closed 3 years ago

PoshAlpaca commented 3 years ago

Expected Behavior (Mandatory)

The cypher file gets executed without any errors by cypher-shell and the backed up data is properly recreated.

Actual Behavior (Mandatory)

Cypher-shell returns a "Failed to evaluate expression" error and exits.

How to Reproduce the Problem

The error occurs whenever cypher-shell encounters a :param line that contains a function like datetime('2020-11-23T22:21:02.554Z'). These :param lines are generated by the apoc.export.cypher.all function when run with UNWIND_BATCH_PARAMS optimizations enabled.

Steps (Mandatory)

  1. Create a node with a property of type DateTime e.g. CREATE (:TestNode {created: datetime()})
  2. Run CALL apoc.export.cypher.all('backup.cypher', {useOptimizations: {type: 'UNWIND_BATCH_PARAMS', unwindBatchSize:100}})
  3. Run the generated backup.cypher with cypher-shell: cat backup.cypher | cypher-shell

Specifications (Mandatory)

Currently used versions

Versions

conker84 commented 3 years ago

@PoshAlpaca thank you for reaching us, can you share a simple dataset that allows us to reproduce the problem?

PoshAlpaca commented 3 years ago

This occurs when exporting a graph of any size as long as there is a property somewhere with the DateTime type. So starting from an empty graph, creating a node with CREATE (:TestNode {created: datetime()}) and then exporting with CALL apoc.export.cypher.all('backup.cypher', {useOptimizations: {type: 'UNWIND_BATCH_PARAMS', unwindBatchSize:100}}) should produce the following cypher script that causes the cypher-shell error:

:begin
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
:begin
:param rows => [{_id:1, properties:{created:datetime('2020-11-26T21:36:04.212Z')}}]
UNWIND $rows AS row
CREATE (n:`UNIQUE IMPORT LABEL`{`UNIQUE IMPORT ID`: row._id}) SET n += row.properties SET n:TestNode;
:commit
:begin
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 20000 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
:commit
:begin
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT (node.`UNIQUE IMPORT ID`) IS UNIQUE;
:commit
vga91 commented 3 years ago

@PoshAlpaca the bug seems to be caused by cypher-shell. I have opened a related issue https://github.com/neo4j/cypher-shell/issues/286