Neo4j LOADCSV - 多个节点中的拆分列

时间:2017-05-27 17:51:07

标签: neo4j cypher

我有一个CSV文件,其中包含以下标题和行:

Person,Vehicle
John,2006 Toyota Corola
Rick,2014 Honda Civic
Mary,2015 BMW 5Series

我希望能够创建以下节点

Person: {John, Rick, Mary}
CarMaker: {Toyota, Honda, BMW}
CarModel: {"Year:2006,Name:Corola", "Year:2014, Name:Civic", "Year:2015, Name:5 Series"}

以下关系:

CarMaker-[:MAKES]->CarModel
Person-[:DRIVES]->CarModel

我使用以下声明:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///FakeNulls.csv" AS line
MERGE (person:Person {name: line.Person})
WITH (SPLIT(line.Vehicle," ") AS words |
UNWIND words AS word |
MERGE (carMaker:CarMaker {carMakerName:word[1]})
MERGE (carModel:CarModel {carModelName:word[2], carModelYear:word[0]})
MERGE (carMaker)-[:MAKES]->(carModel)
MERGE (person)-[:DRIVES]->(carModel))

然而,当我运行它时,我收到一个错误:

Invalid input 'S': expected 'n/N' (line 34, column 32 (offset: 1948))
"WITH (SPLIT(line.Vehicle," ") AS words |"

关于我做错的任何想法?

提前感谢您的帮助。

-MD

1 个答案:

答案 0 :(得分:0)

你有一些奇怪的和语法上无效的括号和|您的查询中的字符以及没有任何意义的UNWIND,因为您已经在集合中使用索引来获取所需的值。

尝试此查询的固定版本:

USING PERIODIC COMMIT 1000
LOAD CSV WITH HEADERS FROM "file:///FakeNulls.csv" AS line
MERGE (person:Person {name: line.Person})
WITH person, SPLIT(line.Vehicle," ") AS word
MERGE (carMaker:CarMaker {carMakerName:word[1]})
MERGE (carModel:CarModel {carModelName:word[2], carModelYear:word[0]})
MERGE (carMaker)-[:MAKES]->(carModel)
MERGE (person)-[:DRIVES]->(carModel)