我有这个查询 -
LOAD CSV from "file:/C:/1m/movies1.csv" AS rows
FIELDTERMINATOR ';' unwind rows as row
foreach (r in row|
SPLIT(r[3],"|") as genre
merge (c:Genres { name: genre })
merge (m:Movies { MovieID: row[1] })
MERGE (m)-[:HAS_GENRE]->(c))
行是这样的 -
1;Toy Story (1995);Animation|Children's|Comedy
2;Jumanji (1995);Adventure|Children's|Fantasy
3;Grumpier Old Men (1995);Comedy|Romance
4;Waiting to Exhale (1995);Comedy|Drama
所以每行的第三个元素都有多个值,我想用'|'来展开分隔符。但我得到错误 -
Invalid input 'P': expected 't/T' or 'e/E' (line 4, column 2 (offset: 108))
"SPLIT(r[3],"|") as genre"
如何拆分每行中的第三项并将它们合并到一个节点?
答案 0 :(得分:5)
一般来说,FOREACH的东西可以用UNWIND完成。
LOAD CSV from "file:/C:/1m/movies1.csv" AS rows FIELDTERMINATOR ';'
MERGE (movie:Movie {MovieID:rows[0]})
SET movie.name = rows[1]
WITH movie, SPLIT(rows[2], "|") AS genres
UNWIND genres AS g
MERGE (genre:Genre {name:g})
MERGE (movie)-[:HAS_GENRE]->(genre)
RETURN movie, genre;
收率:
您还指的是rows[3]
,它是null。 csv文件只有3列,其中第三列是rows[2]
访问的。