Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-14-2021 05:49 PM
Hi everyone!
I've created one specific relationship type based on the imported .csv file:
LOAD CSV WITH HEADERS FROM "file:///file.csv" AS csvLine
MATCH (c1:Country {CountryISO3Digit: csvLine.i}), (c2:Country {CountryISO3Digit: csvLine.j})
CREATE (c1)-[:EXPORTED {Year: datetime(csvLine.t), ProductHSCode: csvLine.k, ProductValue: toFloat(csvLine.v), ProductQuantity: toFloat(csvLine.q)}]->(c2)
Nodes are countries and relationship links are product trades between the countries. I would like to create a new relationship type based on a condition which will annotate a subset of links from the existing relationship type "EXPORTED". For example, i would like to generate a new relationship type based on the exported product code, but without creating a new relationships!
The following query isn't working. Please help!
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country) WHERE r.ProductHSCode="123456"
SET (c1:Country)-[r:EXPORTED_PRODUCT_123456]->(c2:Country)
Solved! Go to Solution.
11-15-2021 09:23 PM
Try this: Add a new property
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country) WHERE r.ProductHSCode="123456"
SET r.exportedProduct = "123456"
To search on this:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
where r.exportedProduct is not null and r.exportedProduct = "123456"
RETURN c1, c2
11-15-2021 11:47 AM
You'll want to use apoc.refactor.setType(). Although all it is doing under the hood is re-creating a new relationship with the name you pass it. So ID(r:EXPORTED) != ID(r:EXPORTED_PRODUCT_123456)
. Otherwise, there is no way to directly change the type of a relationship.
11-16-2021 05:37 PM
You'll want to use apoc.refactor.setType(). Although all it is doing under the hood is re-creating a new relationship with the name you pass it. So
ID(r:EXPORTED) != ID(r:EXPORTED_PRODUCT_123456)
. Otherwise, there is no way to directly change the type of a relationship.
@seankrobinson does that mean that the r:EXPORTED wouldn't consist anymore of the links which will be "transfered" into r:EXPORTED_PRODUCT_123456?
Try this: Add a new property
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country) WHERE r.ProductHSCode="123456"
SET r.exportedProduct = "123456"
To search on this:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
where r.exportedProduct is not null and r.exportedProduct = "123456"
RETURN c1, c2
@ameyasoft, i managed to get this, thanks. May i ask why are you using "not null", there shouldn't be any nulls either way?
Do you guys think that the first solution (ie. creating new relationship type) would yield better querying performance?
11-16-2021 06:58 PM
May i ask why are you using "not null", there shouldn't be any nulls either way?
This new property will be added to "EXPORTED" relationship only under certain conditions like "123456". Otherwise this new property will not be available in all other 'EXORTED' relationships. Where it is not null syntax is a new version of old 'where exists'. By using this you will be filtering out the relationships where this new property exists.
11-17-2021 04:09 PM
Hi @ameyasoft thanks for the clarification! One more question though:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
where r.exportedProduct = "123456"
RETURN c1, c2
Wouldn't this filter imply by itself that only "exportedProduct" property is selected and therefore null values aren't selected by default?
11-18-2021 02:56 PM
Yes, it should work.
11-15-2021 09:23 PM
Try this: Add a new property
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country) WHERE r.ProductHSCode="123456"
SET r.exportedProduct = "123456"
To search on this:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
where r.exportedProduct is not null and r.exportedProduct = "123456"
RETURN c1, c2
All the sessions of the conference are now available online