Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-11-2019 10:00 AM
This is my first time to use NEO4J with almost zero experience. I got error when run the following:
LOAD CSV WITH HEADERS FROM "file:///C:/sample3.csv" as line
MERGE (a:test2 {Name:line.ANI})
MERGE (b:test2 {Name:line.CUST})
MERGE (c:test2 {Name:line.ESN})
MERGE (d:test2 {Name:line.CUST2})
MERGE (a) -[:calls {test:line.L1}]-> (b)
MERGE (b) -[:esn {test:line.L2}]-> (c)
MERGE (c) -[:test_accounts {swap:line.L3 }]-> (d)
Neo.ClientError.Statement.SemanticError
Cannot merge node using null property value for Name
I know the reason is there are maybe NULL values in node d and L3.
I am not sure how to fix this to display the graph when node d and L3 do give you values.
Appreciate any suggestion and syntax help.
11-11-2019 11:17 AM
you can have the LOAD CSV
not parse the row given a condition, for example
LOAD CSV WITH HEADERS FROM "file:///C:/sample3.csv" as line
with line where line.L3 is not null
MERGE (a:test2 {Name:line.ANI})
MERGE (b:test2 {Name:line.CUST})
MERGE (c:test2 {Name:line.ESN})
MERGE (d:test2 {Name:line.CUST2})
MERGE (a) -[:calls {test:line.L1}]-> (b)
MERGE (b) -[:esn {test:line.L2}]-> (c)
MERGE (c) -[:test_accounts {swap:line.L3 }]-> (d)
11-11-2019 03:14 PM
Alternately, if only d
and line.L3
can be null, only move them to the end, with the WHERE condition filtering rows out just before so all the other MERGEd nodes and relationships happen first:
LOAD CSV WITH HEADERS FROM "file:///C:/sample3.csv" as line
MERGE (a:test2 {Name:line.ANI})
MERGE (b:test2 {Name:line.CUST})
MERGE (c:test2 {Name:line.ESN})
MERGE (d:test2 {Name:line.CUST2})
MERGE (a) -[:calls {test:line.L1}]-> (b)
MERGE (b) -[:esn {test:line.L2}]-> (c)
WITH line
WHERE line.CUST2 IS NOT NULL
MERGE (d:test2 {Name:line.CUST2})
WITH line, d
WHERE line.L3 IS NOT NULL
MERGE (c) -[:test_accounts {swap:line.L3 }]-> (d)
Be aware there are Eager operators in the query plan here, you might want to consider multiple passes over the CSV to handle loading nodes first with CREATE or MERGE, one pass per column used for creation. This would only apply where the labels are the same (in your example case, all are :test2
, driving the use of Eager).
Here's a blog entry on Eager operators in the query, what they are, what their consequences are, why they happen, and how to avoid them.
All the sessions of the conference are now available online