theMadKing
theMadKing

Reputation: 2074

Neo4j CSV Import with multiple Where

So I am importing a rather robust CSV with tons of information in it. Rather than slicing it and reduplicating a lot of data and cleansing does Neo4j support a where clause in a multiple way for instance:

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"

Than additionally add another:

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

Making a much larger clause?

Upvotes: 2

Views: 649

Answers (1)

stdob--
stdob--

Reputation: 29147

Use a combination of CASE and FOREACH:

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]})
)

Taken from Mark Needham. Neo4j: LOAD CSV – Handling empty columns

Upvotes: 2

Related Questions