Reputation: 679
I am new to the cypher query era.
I am trying to load csv and creating the relation between two nodes based on match. Match between two need is depend on csv data, csv has assignment data like,
Id,EmployeeId,DepartmentId,AppId,Name
11, 222, ,2, abc
12, , 433, pqr
13, , , xyz
I have to build relation between Application
Node and Employee
Node.
So my query is like,
LOAD CSV WITH HEADERS FROM 'file:///assignment.csv' as ass
MATCH(c:Application),(e:Employee)
WHERE
c.appId = ass.AppId
AND
e.employeeId= ass.employeeId AND e.departmentId= ass.departmentId // line 6
// here in line 6, condition should be based on null values of employeeId and departmentId
MERGE (e)-[r: OWNS
{assignment_id: ass.ID}]->(c)
For some assignments employeeId can be null so in this case line 6 condition like
e.departmentId= ass.departmentId
For some assignments departmentId can be null so in this case line 6 condition like
e.employeeId= ass.employeeId
For some cases both employeeId and departmentId can be null so that case, there should be any condtion or can be true=true
I tried for ForEach(), UNWIND but got the syntax error. I tried with CASE WHEN conditioning but got the syntax error.
Upvotes: 0
Views: 142
Reputation: 793
Here are three options;
create the CSV omitting the rows with null values.
create the nodes and then add (using set) the properties, the latter skipping nodes without the property.
use a case statement to set default values for nulls. An example of the query from one of my projects
merge (f:DNA_Match{fullname:trim(toString(case when line.First_Name is null then '' else line.First_Name end + case when line.Middle_Name is null then '' else ' ' + line.Middle_Name end + case when line.Last_Name is null then '' else ' ' + line.Last_Name end))}) set f.first_name=toString(case when line.First_Name is null then '' else line.First_Name end), f.middle_name=toString(case when line.Middle_Name is null then '' else line.Middle_Name end), f.surname=trim(toString(case when line.Last_Name is null then '' else line.Last_Name end))
Upvotes: 0