我有一个看起来像这样的CSV文件
id;title;startdate;enddate;budget;description;department;supervisor;supervisor_email;member;member_email;tags
49206;Some title;29.09.2015;27.04.2016;4 billion;Something about the title;ABC;Person1;person1@aol.com;Person2, Person3;person2@aol.com, person3@aol.com;Some tags
8501;Some Title2;13.07.2015;15.02.2016;14 billion;Something about Title2;DEF;Person4;person4@aol.com;Person5, Person6;person5@aol.com, person6@aol.com;Title2
我写了以下Cypher
LOAD CSV WITH HEADERS FROM 'file:///..../Project.csv' AS row FIELDTERMINATOR ';'
MERGE (pr:Project {projectID: row.id, title: row.title, startdate: row.startdate, enddate: row.enddate, budget: row.budget})
FOREACH (n IN row.member_email |
WITH SPLIT(row.member_email, ", ") AS memberEmails
MERGE (p:Person {email: memberEmails})
MERGE (p)-[:IS_MEMBER]->(pr)
)
我们可以看到成员电子邮件地址用逗号分隔,我想拆分电子邮件地址并使用电子邮件地址来匹配该人,以创建项目拥有成员的新关系。
SPLIT
和FOREACH
正在制造冲突,我无法理解原因。真的很感激,如果有人能帮助我。
答案 0 :(得分:1)
尝试使用UNWIND:
LOAD CSV WITH HEADERS FROM 'file:///..../Project.csv' AS row FIELDTERMINATOR ';'
MERGE (pr:Project {projectID: row.id, title: row.title, startdate: row.startdate, enddate: row.enddate, budget: row.budget})
WITH pr, SPLIT(row.member_email, ", ") AS memberEmails
UNWIND memberEmails as email
MERGE (p:Person {email: email})
MERGE (p)-[:IS_MEMBER]->(pr)
答案 1 :(得分:0)
LOAD CSV WITH HEADERS FROM 'file:///..../Project.csv' AS row FIELDTERMINATOR ';'
MERGE (pr:Project {projectID: row.id, title: row.title, startdate: row.startdate, enddate: row.enddate, budget: row.budget})
WITH pr, SPLIT(row.member_email, ", ") AS memberEmails
UNWIND memberEmails as email
FOREACH (n IN memberEmails | MERGE (p:Person {email: email}) MERGE (p)-[:IS_MEMBER]->(pr) )