Reputation: 567
I am loading a basic CSV file into Neo4j database which has got two columns - "name" and "property". The name column always has a value and "property" column can either have a value or a blank space. I would like to values to be linked with a relationship "property1".
I am using this code:
LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
MERGE (Test_Document:A {name: line.name})
WITH line, Test_Document
FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
MERGE (Properties:B {property1: line.property})
WITH Test_Document, Properties
FOREACH (y IN CASE WHEN Properties IS NULL THEN [] ELSE [1] END |
MERGE (Test_Document)-[:property1]->(Properties))
I am getting an error message:
Unexpected end of input: expected whitespace, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN or ')' (line 8, column 54 (offset: 423))
" MERGE (Test_Document)-[:property1]->(Properties))"
Any help would be appreciated.
Upvotes: 2
Views: 1595
Reputation: 21552
Another approach would use WHERE
to create relationships only when there are not with missing values as:
LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
WITH line, line.name AS Name, line.property AS Property
MERGE (Test_Document:A {name: Name})
WITH Property
WHERE Property <> ""
MERGE (Properties:B {property1: Property})
MERGE (Test_Document)-[:property1]->(Properties)
This creates the link and the B node only when the property field is not null.
Upvotes: 3
Reputation: 8546
There are two problems with your query:
Properties
is not in scope for the second FOREACH
since it is declared in the previous FOREACH
(aliases declared within a FOREACH
are only scoped to within that FOREACH
clause)Try this:
LOAD CSV WITH HEADERS FROM 'file:///fileName.csv' AS line
MERGE (Test_Document:A {name: line.name})
WITH line, Test_Document
FOREACH (x IN CASE WHEN line.property IS NULL THEN [] ELSE [1] END |
MERGE (Properties:B {property1: line.property})
MERGE (Test_Document)-[:property1]->(Properties)
)
Upvotes: 4