Load CSV with empty cells

(Ahmedmelmoselhy) #1

Hello everyone, I am trying to load simple data from CSV to Noe4j, but it keeps giving me this error
"Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for Name"

I don't have null values in my file !!. Even if I will have, how to deal with it?
This is the code

Blockquote

LOAD CSV WITH HEADERS FROM "file:///new.csv" as line
MERGE (p:per {Name:line.person})
MERGE (m:mang {Name:line.mang})
MERGE (p) -[:S {Name:line.Score}]-> (m)

Blockquote
and this is my csv file
image

(Andrew Bowman) #2

As for nulls, null in Neo4j is the equivalent of there being no property at all. In this case I'm guessing you have blank lines in your CSV. You may need to inspect it in a text editor and delete the blank lines.

You can always get around this by adding a WHERE clause into the query:

LOAD CSV WITH HEADERS FROM "file:///new.csv" as line
WITH line
WHERE line.person IS NOT NULL
MERGE (p:per {Name:line.person})
MERGE (m:mang {Name:line.mang})
MERGE (p) -[:S {Name:line.Score}]->(m)
2 Likes
(DKumar) #3
  1. Do you have an extra spaces or return at the end of the file ?
  2. Do you want to skip all the empty persons ?
  3. Do you want to replace any empty persons with some "NA" data ?
1 Like
(Ahmedmelmoselhy) #4

Thanks for the prompt response.
I found the issue with Microsoft Excel and solved it.
but I have another case which looks like the following:

LOAD CSV WITH HEADERS FROM "file:///new.csv" as line
MERGE (p:per {Name:line.person})
MERGE (m:mang {Name:line.mang})
MERGE (c:com {Name:line.comp})
MERGE (p) -[:S {Name:line.Score}]-> (m)
MERGE (p) -[:Works_For ]-> (c)

This is the csv file
image

in this case, I want to create that graph like this
image
(i.e I want to create the partially filed record (row #3 in my file) without creating a node for the empty cell in "comp" column)
"I don't want to neglect the whole record in case it contains some empty cells"

(Ahmedmelmoselhy) #5

Thanks for the reply.
I solved the leading/extra spaces issue but now my concern is what I mentioned in my last reply.

(Paul Drangeid) #6

For any lines that may contain nulls, you can check before your MERGE statement (note the closing parentheses at the end):

FOREACH (ignoreMe in CASE WHEN exists(line.comp) THEN [1] ELSE [] END |MERGE (c:com {Name:line.comp}) MERGE (p) -[:Works_For ]-> (c))
FOREACH (ignoreMe in CASE WHEN exists(line.Score) THEN [1] ELSE [] END |MERGE (m:mang {Name:line.mang}) MERGE (p) -[:S {Name:line.Score}]-> (m))
1 Like
(Ahmedmelmoselhy) #7

pdrangeid
Thank you very much, I tried it and it is working now :slight_smile: