2016-05-20 2 views
1

Also importiere ich eine ziemlich robuste CSV mit Tonnen von Informationen darin. Anstatt es und reduplicating eine Menge Daten und Reinigung Schneiden tut Neo4j eine where-Klausel in einer mehr Art und Weise zum Beispiel unterstützen:Neo4j CSV-Import mit mehreren Wo

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" 

als zusätzlich ein weiteren hinzu:

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

eine viel größere Klausel zu machen?

Antwort

1

Verwenden Sie eine Kombination aus CASE und 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]}) 
) 

Entnommen Mark Needham. Neo4j: LOAD CSV – Handling empty columns