Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-07-2022 07:47 AM
Hi!, Given that I have created nodes and relationships from the "example.csv" file as below. However, I have a new file, "other_names.csv", with the family_names in example.csv as column heads with a series of first_names under each column.
Any HINT/SUGGESTION on how to –> MATCH AND MERGE<– without individually creating nodes for each column, like row.Dickens , row.Wang etc. ? Thanks
"LOAD CSV WITH HEADERS FROM $path AS row "
"MERGE (f:family_name {name: row.family_name}) "
"MERGE (fn:first_name {name: row.first_name}) "
"MERGE (h:hometown {name: row.hometown}) "
"MERGE (r:race {name: row.race}) "
"MERGE (a:age {name: row.age}) "
"MERGE (o:occupation {name: row.occupation}) "
"MERGE (f)-[:first_name_is]->(fn) "
"MERGE (fn)-[:commonly_from]->(h) "
"MERGE (f)-[:often_associated_the_race]->(r) "
"MERGE (fn)-[:age_is]-(a) "
"MERGE (fn)-[:works_as]->(o) "
#Neo4j #CSV #GraphDatabase
Solved! Go to Solution.
12-07-2022 09:09 PM
Try this:
load csv from "file:///other_names.csv" as row
with row as headerRow
limit 1
load csv from "file:///other_names.csv" as row
with headerRow, row
skip 1
unwind range(0,size(headerRow)-1) as index
merge(f:family_name{name:headerRow[index]})
merge(fn:first_name{name:row[index]})
merge (f)-[:first_name_is]->(fn)
12-07-2022 10:21 AM
how do you want the new data related to the existing data?
12-07-2022 04:33 PM - edited 12-07-2022 04:59 PM
I want to update this relationship "MERGE (f)-[:first_name_is]->(fn) " from the file other_names.csv
12-07-2022 07:47 PM
Do you want to related each first name in each column to their corresponding family name node specified in the column header?
12-07-2022 07:51 PM - edited 12-07-2022 07:52 PM
`that's correct. `those column headers have already been established as nodes in example.csv so i need to match and merge them from this new CSV file
12-07-2022 09:09 PM
Try this:
load csv from "file:///other_names.csv" as row
with row as headerRow
limit 1
load csv from "file:///other_names.csv" as row
with headerRow, row
skip 1
unwind range(0,size(headerRow)-1) as index
merge(f:family_name{name:headerRow[index]})
merge(fn:first_name{name:row[index]})
merge (f)-[:first_name_is]->(fn)
12-07-2022 11:05 PM
Thanks @glilienfield
the first line should be this instead, right?
Cannot merge the following node because of null property value for 'name': (:family_name {name: null})
12-09-2022 08:39 PM
@glilienfield with reference to these files”—-Considering that I want to skip all the null values , what’s the best way to tackle it. I tried use the “is null approach” but failed to get it right.
12-10-2022 04:11 AM
You had change the starting index to one. Is there a column of row numbers in the first column? If so, this column does not have a header and would explain that null value error, which occurred for the family name (header values).
Are there null values in the row data?
12-10-2022 04:24 AM - edited 12-10-2022 04:26 AM
The case I presented earlier was just a sample case to help do a knowledge transfer. The real data I am working on looks something like this (48 columns):
12-10-2022 05:51 AM
There are three approach I can think of for dealing with null values during import: 1) coalesce to set a default value, 2) call subquery testing for null condition, and 3) apoc.do.when
https://neo4j.com/labs/apoc/4.1/overview/apoc.do/apoc.do.when/
do you want to work on the actually query?
12-08-2022 04:28 PM
@glilienfield pardon me, how come when you paste your codes, they appear in a block form (image kind of)? any trick there? 😬
12-08-2022 05:09 PM
yes...you need to paste the code in the a code block. First, click on the ellipse symbol in the tool bar (far left - see figure)
Next, click on the code block symbol '</>':
12-08-2022 05:27 PM
Alright, let me try, 😎
MATCH (f:flows)-[r]->(f2)
UNWIND keys({mat: 's', pro: 'p', feat: 'd'}) AS keyword
WITH f, f2, r, keyword
WHERE({mat: 's', pro: 'p', feat: 'd'})[keyword] <> '' AND type(r) = keyword AND f2.name CONTAINS {mat: 's', pro: 'p', feat: 'd'}[keyword]
WITH f.name as text, count(*) AS c ORDER BY c DESC, size(text) ASC
RETURN text
All the sessions of the conference are now available online