Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-20-2019 06:12 AM
Hello, I have a problem :
I'm working on a Graph with Countries of the world
I use this Cypher command :
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
create (cap:Capitale {name: line.capital})
create (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
create (cont:Continent {name: line.continent})
create (o:Ocean {name: line.ocean})
create (i:Iles {name: line.iles})
create (org:Organisme {name: line.organisme})
create (langPrinc:LanguePrincipale {name: line.languePrincipale})
create (langSec:LangueSecondaire {name: line.autreLangue})
create (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
create (gouv:Gouvernance {name: line.gouvernance})
create (m:Monnaie {name: line.monnaie})
create (dev:Devise {name: line.devise})
create (cap)-[:CAPITALE_DE]->(p)
create (langPrinc)-[:SPOKE]->(p)
create (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
create (o)-[:BORDE]->(p)
create (p)-[:POSSEDE]->(i)
create (d)-[:DIRIGE]->(p)
create (m)-[:EST_LA_MONNAIE]->(p)
create (dev)-[:EST_LA_DEVISE]->(p)
create (p)-[:EST_SUR_CONTINENT]->(cont)
create (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
create (dir)-[:MEMBRE_DE]->(org)
create (gouv)-[:SIEGE_A]->(cap)
When i start a Query to find all countries which speak english, I use this query : (Country)-[SPOKE]->(English)
The problem is : instead of creating one node with the langage ( here english ), and all the countries which speak this language around, it creates me tons of "english" node, each one linked to only one country
I use an CSV file to organise my data. And i already try to remplace all my CREATE by MERGE but i have an error : Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for name.
So i'm really stuck,
Thank for your help , I'm not english, if you need more distinct info, I can try again to explain
Solved! Go to Solution.
06-20-2019 03:37 PM
Your test.csv file has null/no data for one or more columns on any row. There are two ways to handle this.
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line WHERE line.pays is NOT NULL
MERGE (cap:Capitale {name: line.capital}).......
MERGE (gouv)-[:SIEGE_A]->(cap)
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line
MERGE (cap:Capitale {name: line.capital})
MERGE (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
MERGE (cont:Continent {name: line.continent})
MERGE (o:Ocean {name: line.ocean})
MERGE (i:Iles {name: line.iles})
MERGE (org:Organisme {name: line.organisme})
// when line.languePrincipale has some value......
FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NOT NULL THEN [1] ELSE END |
MERGE (langPrinc:LanguePrincipale {name: line.languePrincipale})
MERGE (langPrinc)-[:SPOKE]->(p)
)
// when line.languePrincipale has no value...... NA (Not Available). Use this if you want to create language node with NA value.
FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NULL THEN [1] ELSE END |
MERGE (langPrinc:LanguePrincipale {name: "NA"})
MERGE (langPrinc)-[:SPOKE]->(p)
)
MERGE (langSec:LangueSecondaire {name: line.autreLangue})
MERGE (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
MERGE (gouv:Gouvernance {name: line.gouvernance})
MERGE (m:Monnaie {name: line.monnaie})
MERGE (dev:Devise {name: line.devise})
MERGE (cap)-[:CAPITALE_DE]->(p)
MERGE (langPrinc)-[:SPOKE]->(p)
MERGE (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
MERGE (o)-[:BORDE]->(p)
MERGE (p)-[:POSSEDE]->(i)
MERGE (d)-[:DIRIGE]->(p)
MERGE (m)-[:EST_LA_MONNAIE]->(p)
MERGE (dev)-[:EST_LA_DEVISE]->(p)
MERGE (p)-[:EST_SUR_CONTINENT]->(cont)
MERGE (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
MERGE (dir)-[:MEMBRE_DE]->(org)
MERGE (gouv)-[:SIEGE_A]->(cap);
06-20-2019 07:01 AM
You definitely should use MERGE to create the relationships and ideally the nodes also, this will prevent duplicates.
From the error you are seeing, there is data in your CSV file that has no value for name. This is not allowed in a MERGE. Can you clean up the data?
Ideally, you want uniqueness constraints on all of the properties you are using the create the nodes.
Elaine
06-20-2019 03:37 PM
Your test.csv file has null/no data for one or more columns on any row. There are two ways to handle this.
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line WHERE line.pays is NOT NULL
MERGE (cap:Capitale {name: line.capital}).......
MERGE (gouv)-[:SIEGE_A]->(cap)
LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line
MERGE (cap:Capitale {name: line.capital})
MERGE (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
MERGE (cont:Continent {name: line.continent})
MERGE (o:Ocean {name: line.ocean})
MERGE (i:Iles {name: line.iles})
MERGE (org:Organisme {name: line.organisme})
// when line.languePrincipale has some value......
FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NOT NULL THEN [1] ELSE END |
MERGE (langPrinc:LanguePrincipale {name: line.languePrincipale})
MERGE (langPrinc)-[:SPOKE]->(p)
)
// when line.languePrincipale has no value...... NA (Not Available). Use this if you want to create language node with NA value.
FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NULL THEN [1] ELSE END |
MERGE (langPrinc:LanguePrincipale {name: "NA"})
MERGE (langPrinc)-[:SPOKE]->(p)
)
MERGE (langSec:LangueSecondaire {name: line.autreLangue})
MERGE (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
MERGE (gouv:Gouvernance {name: line.gouvernance})
MERGE (m:Monnaie {name: line.monnaie})
MERGE (dev:Devise {name: line.devise})
MERGE (cap)-[:CAPITALE_DE]->(p)
MERGE (langPrinc)-[:SPOKE]->(p)
MERGE (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
MERGE (o)-[:BORDE]->(p)
MERGE (p)-[:POSSEDE]->(i)
MERGE (d)-[:DIRIGE]->(p)
MERGE (m)-[:EST_LA_MONNAIE]->(p)
MERGE (dev)-[:EST_LA_DEVISE]->(p)
MERGE (p)-[:EST_SUR_CONTINENT]->(cont)
MERGE (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
MERGE (dir)-[:MEMBRE_DE]->(org)
MERGE (gouv)-[:SIEGE_A]->(cap);
06-21-2019 01:19 AM
Thank a lot you solve my problem !
All the sessions of the conference are now available online