Thank you so much for your reply. I haven't really started learning apoc, i am just first trying to get familiar with cypher before i move to apoc.
I think the problem i have is the way i am finding the last non empty cell. The following is the code i used, I am getting the correct parent child relationship between task-subtask1-subtask2-sub_task3. The problem is I am getting a relationship created with expertise and a the last non empty cell and all its parents which i don't want. I would really appreciate it if you can give me any advice on my code . Thanks
The output that I want is
A<-[:CHILD_OF]-A1<-[:CHILD_OF]-A2<-[:CHILD_OF]-A3-[:EXPERT]->expertise
B<-[:CHILD_OF]-B1<-[:CHILD_OF]-B2-[:NOVICE]->expertise
C<-[:CHILD_OF]-C1-[:NOVICE]->expertise
CREATE (e:Expertise {name:'Expertise'})
LOAD CSV WITH HEADERS FROM ‘test.csv' AS row
WITH row
MATCH(e:Expertise)
WHERE row.Task IS NOT NULL
MERGE (t:Task {name: row.Task})
// if Subtask1 field is not empty, then create that node and create parent-child relationship to the Task
FOREACH (x1 in SPLIT(row.sub_task1 , ',') |
MERGE (s1:S1 {name:x1}) MERGE (t)-[:HAS_CHILD]->(s1)
// if Subtask2 field is not empty, then create that node and create parent-child relationship to the S1
FOREACH (x2 in SPLIT(row.sub_task2 , ',') |
MERGE (s2:S2 {name:x2}) MERGE (s1)-[:HAS_CHILD]->(s2)
// if Subtask3 field is not empty, then create that node and create parent-child relationship to the S2
FOREACH (x3 in SPLIT(row.sub_task3 , ',') |
MERGE (s3:S3 {name:x3}) MERGE (s2)-[:HAS_CHILD]->(s3)
// for each expertise, create the relationship to the S3 node (since S3 wasn’t empty)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Expert' THEN [1] ELSE END |
MERGE (s3)-[n:EXPERT]->(e)
)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Novice' THEN [1] ELSE END |
MERGE (s3)-[n:NOVICE]->(e)
)
) //S3
// for each expertise, create the relationship to the S2 node (since S2 wasn’t empty and S3 was empty)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Expert' THEN [1] ELSE END |
MERGE (s2)-[n:EXPERT]->(e)
)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Novice' THEN [1] ELSE END |
MERGE (s2)-[n:NOVICE]->(e)
)
)//S2
// for each expertise, create the relationship to the S1 node (since S1 wasn’t empty and S2 was empty)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Expert' THEN [1] ELSE END |
MERGE (s1)-[n:EXPERT]->(e)
)
FOREACH (ignoreMe in CASE WHEN row.Expertise = 'Novice' THEN [1] ELSE END |
MERGE (s1)-[n:NOVICE]->(e)
)
)//S1
RETURN c