Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-13-2022 01:19 AM
Please, I need help.
I have a node labelled sp:specific_process. sp has properties, including location. Which was set as :
MERGE (sp:specific_process {name:row.process})
SET sp.Id = row.id, sp.Name = row.name, sp.Description = row.description, sp.Process_Type = row.processType,sp.Last_Change = row.lastChange, sp.Version = row.version,sp.Location = row.location, sp.Category = row.category
from the relational database, I am hoping to retrieve the locations in a set order. Considering that some locations are grouped, for instance, a location could be {Location: China, India, Japan}. So I use the approach below, and I get no error, but my output is nothing,i.e. –––– (no changes, no records)–––––– Individually, I can retrieve the locations, but if grouped then no output.
MATCH (sp:specific_process)
WHERE sp.Location CONTAINS 'China'
AND sp.Location CONTAINS 'Asia'
AND sp.Location CONTAINS 'Rest-of-World'
AND sp.Location CONTAINS 'Global'
WITH sp,
CASE sp.Location
WHEN 'China' THEN 1
WHEN 'Asia' THEN 2
WHEN 'Rest-of-World' THEN 3
ELSE 4
END AS Location_rank
RETURN sp.Location
ORDER BY Location_rank ASC
Thanks.
#neo4j #Graphdatabase #CSV
Solved! Go to Solution.
12-13-2022 02:47 AM
Hi Reuben,
so, what is your exact datatype on Location? As I understand it is a String (?) which might look like an array but it is NOT an array, correct? You can use "split" to read in an array from your relational database to create an array in the property in Neo4j as well!
Regardless: your query cannot work as it is. You are looking for a node where the Location property contains 'China', 'Asia', 'Rest-of-World' AND (!!!) 'Global'. And then you are doing a switch case on one of the Strings, i.e. you are saying IF it is 'China' then do something. But it can never be 'China' because in your filtering at the top you are looking for only nodes that have ALL of the four Strings as part of your Location string.
I think what you actually want is to transform your filtering to contain "OR"s and modify your Case statement a bit. Try this:
MATCH (sp:specific_process)
WHERE sp.Location CONTAINS 'China'
OR sp.Location CONTAINS 'Asia'
OR sp.Location CONTAINS 'Rest-of-World'
OR sp.Location CONTAINS 'Global'
WITH sp,
CASE
WHEN sp.Location CONTAINS 'China' THEN 1
WHEN sp.Location CONTAINS 'Asia' THEN 2
WHEN sp.Location CONTAINS 'Rest-of-World' THEN 3
ELSE 4
END AS Location_rank
RETURN sp.Location
ORDER BY Location_rank ASC
As mentioned above you might want to transform the datatype of your Location property to array first.
Regards,
Elena
12-13-2022 02:47 AM
Hi Reuben,
so, what is your exact datatype on Location? As I understand it is a String (?) which might look like an array but it is NOT an array, correct? You can use "split" to read in an array from your relational database to create an array in the property in Neo4j as well!
Regardless: your query cannot work as it is. You are looking for a node where the Location property contains 'China', 'Asia', 'Rest-of-World' AND (!!!) 'Global'. And then you are doing a switch case on one of the Strings, i.e. you are saying IF it is 'China' then do something. But it can never be 'China' because in your filtering at the top you are looking for only nodes that have ALL of the four Strings as part of your Location string.
I think what you actually want is to transform your filtering to contain "OR"s and modify your Case statement a bit. Try this:
MATCH (sp:specific_process)
WHERE sp.Location CONTAINS 'China'
OR sp.Location CONTAINS 'Asia'
OR sp.Location CONTAINS 'Rest-of-World'
OR sp.Location CONTAINS 'Global'
WITH sp,
CASE
WHEN sp.Location CONTAINS 'China' THEN 1
WHEN sp.Location CONTAINS 'Asia' THEN 2
WHEN sp.Location CONTAINS 'Rest-of-World' THEN 3
ELSE 4
END AS Location_rank
RETURN sp.Location
ORDER BY Location_rank ASC
As mentioned above you might want to transform the datatype of your Location property to array first.
Regards,
Elena
12-13-2022 04:45 AM
@elena_kohlwey Please, in using the split() method, do I apply to each row? or just the location row like below:
LOAD CSV WITH HEADERS FROM $path AS row
WITH row
MATCH (n2)
MERGE (sp:specific_process {name:row.process})
SET sp.Id = row.id, sp.Name = row.name, sp.Description = row.description, sp.Process_Type = row.processType,sp.Last_Change = row.lastChange, sp.Version = row.version,sp.Location = row.location.split(","), sp.Category = row.category
12-13-2022 04:49 AM
You only need to apply it to the fields that have arrays in them, so only Location.
But you need to put the argument into the function, i.e.
sp.Location = split(row.location,",")
12-13-2022 04:58 AM
Alright
12-13-2022 03:07 AM
Yes, it's a string. Alright, I will convert them into an array, then. Thanks Elena
12-13-2022 07:14 AM - edited 12-13-2022 05:11 PM
ok
12-13-2022 07:38 AM - edited 12-13-2022 05:11 PM
ok
All the sessions of the conference are now available online