Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-15-2019 12:43 AM
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
Solved! Go to Solution.
02-15-2019 01:37 PM
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))
02-15-2019 01:06 AM
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)
02-15-2019 02:46 AM
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
in this case, I want to create that graph like this
(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"
02-15-2019 02:37 AM
02-15-2019 02:49 AM
Thanks for the reply.
I solved the leading/extra spaces issue but now my concern is what I mentioned in my last reply.
02-15-2019 01:37 PM
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))
11-26-2019 02:23 AM
hi ahmed, i seem to have run into the same problem, any assistance?
12-01-2019 07:09 AM
Sorry olojolabamiji, I didn't notice your comment.
Hope your problem has been solved.
O.W I am here to help.
12-03-2019 07:38 AM
Hi ahmed. Thank you I have been able to solve it. I had to rewrite my code using the SET method.Still on it though.
11-26-2019 02:05 AM
Hi paul, I tried running your code, i have about 9 properties but the first 7 do not have empty spaces.When I run the code as shared it works for the first set of rows of data that has the 8th property value missing but the problems comes when it iterates the second sets of row. I was hoping the for each in case acts like a for loop. would appreciate your help
11-26-2019 08:51 AM
The foreach in case is actually behaving more like an if/then/else statement.
To get true loop behavior in cypher you typically have to use an UNWIND or apoc.periodic.commit
It does sort-of loop (The foreach in case will be evaluated for EACH ROW/MATCH preceding it). In your CASE WHEN condition you can add multiple validations (if this is not null, and that is not null) etc.
The other tricky part to keep in mind is that any variables generated within the statements after the pipe are only available within the parentheses. It will not exist AFTER you close the paren (so you can't use the (c) node from the MERGE statement within the FIRST FOREACH in a subsequent FOREACH unless you add a WITH, and then perform an OPTIONAL MATCH (or often in this case an OPTIONAL MATCH) to capture the variable for use in the subsequent parts of the CYPHER transaction.
If you need a more specific example, please post some sample of the IMPORT data and the CYPHER code you are using and I can take a look.
11-27-2019 01:24 AM
Good morning Paul,
I created a neo4j graph created using the following parameters, which are working fine.This was created using python.
query = """ merge (Name:Name {Name: {a}, Type:{b}, Site:{c}, Title:{d}, Other_names:{e}, Active:{f}})
class.run(query, {"a": row[0], "b": row[1], "c": row[2], "d": row[3], "e": row[4],
"f": row[5], "g": row[6]})
(6 columns). My challenge is to merge it with the below query which only has 3 columns associated with the query with 6 properties .These are Name,Type and Title
query = """
merge(name:name {Name: {a},Type:{b},Title:{c},
status:{d},number:{e},Code:{f},Country:{g},vicinity:{h},Address:{i}})
"""
class.run(query,{"a": Name, "b": Type, "c":Title, "d": status, "e":number, "f":Code,
"g": Country,"h": vicinity,"i":Address})
I want to merge the new query with columns a to i to the existing nodes with columns a to e in the already created database but it doesn't merge .I want to be able to add the new set of properties from the new query to the initial database .It gives this error
py2neo.database.ClientError: SemanticError: Cannot merge node using null property value for Country.
but when i use merge in the same query to create a new graph database,it works without complaining about null properties as long as the initially created database is cleaned out. Please how do I merge my new query to the existing database.
thanks
11-27-2019 05:51 AM
You can't merge using null values.. You can either merge without the null value (then set properties afterwards, or merge and use coalesce to replace null with a placeholder: coalesce({g},'none')
Not a python coder, but check the cypher coalesce statement..
11-28-2019 03:54 AM
Thank you paul.Would take time to rework the code.
All the sessions of the conference are now available online