Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-11-2023 01:01 PM
Solved! Go to Solution.
01-12-2023 06:48 AM
I noticed one oversight. Try these two. they should do the same thing:
WITH 'file:/file_name' AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.nodes AS node
CREATE (n:Node {id: node.id, name: node.name, type: node.type})
WITH distinct value
UNWIND value.edges AS edge
MATCH (source:Node {id: edge.source}), (target:Node {id: edge.target})
MERGE (source)<-[rel:is_part_of]-(target)
CALL apoc.load.json(url) YIELD value
CALL {
with value
UNWIND value.nodes AS node
CREATE (n:Node {id: node.id, name: node.name, type: node.type})
}
CALL {
WITH value
UNWIND value.edges AS edge
MATCH (source:Node {id: edge.source}), (target:Node {id: edge.target})
MERGE (source)<-[rel:is_part_of]-(target)
}
01-11-2023 06:06 PM
I am assuming the json file has a list of node info associated with value.nodes and list of edge info associated with values.edges. The flow of the query unwind the list of node info and creates a node for each. It then passes each created node in its own row with the list of edge info appended to each row. Thus each node row has the identical list of edge information. The unwind edge creates a new row for each edge info in the list and appends the node to each row. As such, the 'unwind edges as edge' operation is repeated over-and-over for each created node. Since you are matching/merging the create the relationship, you don't realize the merge operation is being repeated over-and-over. Removing 'node' from the 'with' will result on only one row being passed, instead of one for each node. Now the 'unwind edges as edge' will occur just once. This should help with issue.
WITH 'file:/file_name' AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.nodes AS node
CREATE (n:Node {id: node.id, name: node.name, type: node.type})
WITH value.edges AS edges
UNWIND edges AS edge
MATCH (source:Node {id: edge.source}), (target:Node {id: edge.target})
MERGE (source)<-[rel:is_part_of]-(target)
01-12-2023 05:21 AM
thank you for your help glilienfield!
I am still running into the same problem and running out of memory:
The allocation of an extra 5.3 MiB would use more than the limit 716.8 MiB. Currently using 712.9 MiB. dbms.memory.transaction.total.max threshold reached
01-12-2023 06:48 AM
I noticed one oversight. Try these two. they should do the same thing:
WITH 'file:/file_name' AS url
CALL apoc.load.json(url) YIELD value
UNWIND value.nodes AS node
CREATE (n:Node {id: node.id, name: node.name, type: node.type})
WITH distinct value
UNWIND value.edges AS edge
MATCH (source:Node {id: edge.source}), (target:Node {id: edge.target})
MERGE (source)<-[rel:is_part_of]-(target)
CALL apoc.load.json(url) YIELD value
CALL {
with value
UNWIND value.nodes AS node
CREATE (n:Node {id: node.id, name: node.name, type: node.type})
}
CALL {
WITH value
UNWIND value.edges AS edge
MATCH (source:Node {id: edge.source}), (target:Node {id: edge.target})
MERGE (source)<-[rel:is_part_of]-(target)
}
01-12-2023 07:41 AM
The first one ran out of memory but the second one worked fine, thank you!
All the sessions of the conference are now available online