0
votes

I need to add more data to a Neo4j database without creating duplicate nodes. Merge should handle this but fails when using CSV load.

I've read several solutions to my problem but they are not working with Neo4j 3.3.3. My CSV file for testing is simple:

Kit|sPOS|ePOS
102866|2781761|2783146
102866|2783227|2783836
102866|2783837|2783841
102866|2783842|2783861
102866|2784027|2790759
102866|2790762|2793652

My Cypher query is:

LOAD CSV WITH HEADERS FROM 'file:///bedupload.csv' AS line
merge (b:BEDNode{sPOS:line.sPOS,ePOS:line.ePOS})
return b

The return is:

Cannot merge node using null property value for sPOS

Thus, it is reading the file, but interpreting it incorrectly. There are no NULL values for sPOS in the CSV.

This Cypher query with create produces the nodes, as expected:

LOAD CSV WITH HEADERS FROM 'file:///bedupload.csv' AS line
create (b:BEDNode{sPOS:line.sPOS,ePOS:line.ePOS})
return b

If I have no properties, a single node is produced as expected:

LOAD CSV WITH HEADERS FROM 'file:///bedupload.csv' AS line
merge (b:BEDNode)
return b

I've tried suggested solutions in various formats with the same NULL error. For instance,

LOAD CSV WITH HEADERS FROM 'file:///bedupload.csv' AS line
merge (b:BEDNode{sPOS:line.sPOS})
on create set b.ePOS=line.ePOS
return b

This seems to be a bug in Neo4j. Looking for help with my error or a workaround.

1
I just noticed that the CREATE query, while producing the nodes, does not create their properties.David A Stumpf

1 Answers

3
votes

LOAD CSV uses comma as the default field terminator. Since you are using pipes you should specify it using FIELDTERMINATOR clause:

LOAD CSV WITH HEADERS FROM 'file:///bedupload.csv' AS line FIELDTERMINATOR '|'
merge (b:BEDNode{sPOS:line.sPOS,ePOS:line.ePOS})
return b