Neo4j CSV导入多个Where

时间:2016-05-20 17:02:03

标签: neo4j

因此,我正在导入一个相当强大的CSV,其中包含大量信息。 Neo4j不是切片并重复大量数据和清理,而是以多种方式支持where子句,例如:

USING PERIODIC COMMIT 1000
LOAD CSV FROM 'file:///registryDump.csv' AS line
WITH line
WHERE line[25] IS NOT NULL
MERGE (u:User {name: line[25]})
ON CREATE SET u.source = "Registry", u.type = "Owner"

比另外添加另一个:

WHERE line[12] IS NOT NULL
MERGE (u:User {name: line[12]})
ON CREATE SET u.source = "Registry", u.type = "Steward"

制定更大的条款?

1 个答案:

答案 0 :(得分:1)

使用CASEFOREACH的组合:

WITH [0,1,null,3] as line
FOREACH(NULL IN CASE WHEN line[0]=0 THEN [1] ELSE [] END |
  MERGE (U:User{name:0})
  ON CREATE SET U.source = "Registry", U.type = "Steward"
)
FOREACH(NULL IN CASE WHEN line[1]<1 THEN [1] ELSE [] END |
  MERGE (U:User{name:1})
)
FOREACH(NULL IN CASE WHEN line[2] IS NOT NULL THEN [1] ELSE [] END |
  MERGE (U:User{name:line[2]})
)
FOREACH(NULL  IN CASE WHEN line[3] IS NOT NULL THEN [1] ELSE [] END |
  MERGE (U:User{name:line[3]})
)

取自Mark Needham. Neo4j: LOAD CSV – Handling empty columns