Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-18-2020 01:57 PM
Hi
I need to creates independent nodes from a csv file, csv is like below-
First, Last, Age
john, Doe, 34
null, Sam,36
My code is like this;
load csv with headers from "file:///demo.csv" as line
with line
CASE
when not line.first is null
CREATE (s:id{name:line.last})
ELSE
CREATE (s:id{name:line.first})
return count(*)
type or paste code here
Expecting it should create independent nodes with first or last name, but I am encountering this error.
Invalid input 'S': expected 'l/L' (line 4, column 3 (offset: 92))
"CASE"
Solved! Go to Solution.
08-18-2020 02:23 PM
Try this:
load csv with headers from "file:///demo.csv" as line
with line
FOREACH(ignoreMe IN CASE WHEN line.first IS NOT NULL THEN [1] ELSE [] END |
MERGE (s:id{name:line.last})
)
FOREACH(ignoreMe IN CASE WHEN line.first IS NULL THEN [1] ELSE [] END |
MERGE (s:id{name:line.first})
)
08-18-2020 02:23 PM
Try this:
load csv with headers from "file:///demo.csv" as line
with line
FOREACH(ignoreMe IN CASE WHEN line.first IS NOT NULL THEN [1] ELSE [] END |
MERGE (s:id{name:line.last})
)
FOREACH(ignoreMe IN CASE WHEN line.first IS NULL THEN [1] ELSE [] END |
MERGE (s:id{name:line.first})
)
08-18-2020 03:41 PM
Thanks it worked,
follow up question,
it took 30 minutes on my desktop to ingest a 5MB csv which had 50k records in it.
I have allocated 12 GB of heal memory.
Is there a way to run it quick or i am doing something wrong ?
08-18-2020 05:04 PM
There is nothing wrong. You can create an index and try it. Also, I do not recommend using 'id' as name label.
08-19-2020 04:33 AM
If you know the values are going to be distinct then you can try this
load csv with headers from "file:///demo.csv" as line
with line
CREATE (s:id{name: coalesce(line.first, line.last)})
If you don't know if it is going to be distinct then you can try
Create index first
CREATE INDEX ON :id(name)
Then run the query
load csv with headers from "file:///demo.csv" as line
with line
MERGE (s:id{name: coalesce(line.first, line.last)})
These should work better.
All the sessions of the conference are now available online