cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

LOAD CSV with null values

Hi,

I am loading a csv that a portion of it looks like below:

1. Report Field 2. Source System Mapping and Transformation Logic 3. Source System  Mapping New Fields 4. Source System FPML
UTI ID   USI normalize-space
USI ID CASE 1
   
   
USI ID Prefix CASE 2    

The nodes would be under the headers in each column, and the relationships would flow from 1. -> 2. -> 3. -> 4. The intent would be to include the blank cells as nodes as placeholders for visualization. However when importing, the first row has no nodes after "UTI ID" and similarly, no blank nodes after "CASE 1" and "CASE 2"

My partial cypher is this:

LOAD CSV WITH HEADERS FROM 'file:///file.csv' AS line
MATCH (fn:FieldName{name: line.`1. Report Field ``})
CREATE (im:SourceSystemMapping:{name: line.`2. Source System Mapping and Transformation Logic)`})
WITH fn, im
CREATE (fn)-[:RELTYPE]-> (im);

LOAD CSV WITH HEADERS FROM 'file:///file.csv' AS line
MATCH (im:SourceSystemMapping:{name: line.`2. Source System Mapping and Transformation Logic)`})
CREATE (jm:SourceSystemCFTC:Murex{name: line.`3. Source System Mapping New Fields`})
WITH im, jm
CREATE (im)-[:RELTYPE]-> (jm);

Is there a conditional clause or FOREACH clause that exists that would include the empty nodes so that the other related nodes are imported?

1 ACCEPTED SOLUTION

ameyasoft
Graph Maven
Try this:
I used your sample data and created this.
LOAD CSV WITH HEADERS FROM 'file:///jcjr.csv' AS line 

with line, COALESCE(line.`1. Report Field`, 'NA1') as col1, COALESCE(line.`2. Source System Mapping and Transformation Logic`, 'NA2') as col2, COALESCE(line.`3. Source System Mapping New Fields`, 'NA3') as col3, COALESCE(line.`4. Source System FPML`, 'NA4') as col4

create (fn:FieldName {name: col1})
create (im:SourceSystemMapping {name:col2})
create (jm:SourceSystemCFTC {name:col3})
create (km:SourceSystemCFPML {name:col4})

create (fn)-[:RELTYPE]-> (im)
create (im)-[:RELTYPE]-> (jm)
create (jm)-[:RELTYPE]-> (km)

Result:

Screen Shot 2023-01-03 at 11.53.13 PM.png

View solution in original post

3 REPLIES 3

Since you want a placeholder node to be created for the null values, the easiest solution is to us ‘coalesce’ to set a default value when the real value is null.  You can also easily identify those nodes that had null values if use a default value that is not a valid value for your data. 

https://neo4j.com/docs/cypher-manual/current/functions/scalar/#functions-coalesce

ameyasoft
Graph Maven
Try this:
I used your sample data and created this.
LOAD CSV WITH HEADERS FROM 'file:///jcjr.csv' AS line 

with line, COALESCE(line.`1. Report Field`, 'NA1') as col1, COALESCE(line.`2. Source System Mapping and Transformation Logic`, 'NA2') as col2, COALESCE(line.`3. Source System Mapping New Fields`, 'NA3') as col3, COALESCE(line.`4. Source System FPML`, 'NA4') as col4

create (fn:FieldName {name: col1})
create (im:SourceSystemMapping {name:col2})
create (jm:SourceSystemCFTC {name:col3})
create (km:SourceSystemCFPML {name:col4})

create (fn)-[:RELTYPE]-> (im)
create (im)-[:RELTYPE]-> (jm)
create (jm)-[:RELTYPE]-> (km)

Result:

Screen Shot 2023-01-03 at 11.53.13 PM.png

This worked great, thank you!