You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
apoc.merge.node allows to dynamically MERGE a node with labels and properties that can be provided as parameters instead of building a static Cyper query beforehand. This is useful in cases where we unwind on multiple rows and the MERGE clause would be different for each row:
In the same way, we can use apoc.merge.relationship to dynamically MERGE a relationship with type and properties provided as parameters. However, we must also provide the start and end node of the relationship. Both nodes can be matched with apoc.merge.node without providing properties to be merge (last two params):
In the second example, I'm using apoc.merge.node to MATCH the start and end nodes without actually creating or changing them. My assumption is though, that Neo4j still write-locks these nodes which affects the performance and would hinder optimisations such as parallelisation via apoc.periodic.iterate due to deadlocks on the same node.
I would like to suggest a new procedure apoc.match.node or apoc.nodes.match to dynamically MATCH nodes. The implementation would be fairly easy as we could copy apoc.merge.node and change the Cypher query in line 77 from MERGE to MATCH:
finalStringcypher = "MERGE (n:" + labels + "{" + identPropsString + "}) ON CREATE SET n += $onCreateProps ON MATCH SET n += $onMatchProps RETURN n";
returntx.execute(cypher, params);
}
Considered alternatives
The default values of apoc.merge.node for onCreateProps and onMatchProps is {}. This means no change to the properties on CREATE or MATCH. Therefore, we could alternatively add condition in Java to check if properties have been provided. If not, we could switch the Cypher query from MERGE to MATCH in this case.
If you find this request useful and would be wiling to add it to APOC, then I would go ahead and submit a PR for this! Let me know what you think! :-)
The text was updated successfully, but these errors were encountered:
Feature description (Mandatory)
apoc.merge.node
apoc.merge.relationship
apoc.merge.node
allows to dynamically MERGE a node with labels and properties that can be provided as parameters instead of building a static Cyper query beforehand. This is useful in cases where we unwind on multiple rows and the MERGE clause would be different for each row:In the same way, we can use
apoc.merge.relationship
to dynamically MERGE a relationship with type and properties provided as parameters. However, we must also provide the start and end node of the relationship. Both nodes can be matched withapoc.merge.node
without providing properties to be merge (last two params):In the second example, I'm using
apoc.merge.node
to MATCH the start and end nodes without actually creating or changing them. My assumption is though, that Neo4j still write-locks these nodes which affects the performance and would hinder optimisations such as parallelisation viaapoc.periodic.iterate
due to deadlocks on the same node.I would like to suggest a new procedure
apoc.match.node
orapoc.nodes.match
to dynamically MATCH nodes. The implementation would be fairly easy as we could copyapoc.merge.node
and change the Cypher query in line 77 from MERGE to MATCH:neo4j-apoc-procedures/core/src/main/java/apoc/merge/Merge.java
Lines 67 to 79 in c56b754
Considered alternatives
The default values of
apoc.merge.node
foronCreateProps
andonMatchProps
is{}
. This means no change to the properties on CREATE or MATCH. Therefore, we could alternatively add condition in Java to check if properties have been provided. If not, we could switch the Cypher query from MERGE to MATCH in this case.If you find this request useful and would be wiling to add it to APOC, then I would go ahead and submit a PR for this! Let me know what you think! :-)
The text was updated successfully, but these errors were encountered: