-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use UNWIND strategy #10
Use UNWIND strategy #10
Conversation
This is somewhat different from upsert_node but it is conceptually still an upsert node operation with a different payload so I've opted to use a kwarg to support this. Neo4j::Http::Client.upsert_node(node, unwind: [{ ... }, { ... }]) The node is still required because we pull some important pieces off of this including the label and key name (primary key)
return node | ||
CYPHER | ||
|
||
results = @cypher_client.execute_cypher(cypher, key_value: node.key_value, batch: unwind) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unwind is an array of node properties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will the whole thing fail if a schema violation happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Tiphani unwind would be an array of Hash objects e.g.
[
{
from: {
uuid: "FromUuid"
},
to: {
uuid: "ToUuid"
},
relationship: {
uuid: "RelationshipUuid",
age: 33
}
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for a schema violation failure, the entire transaction will rollback. I've now added this as a spec
@@ -82,6 +82,26 @@ Neo4j::Http::Client.find_nodes_by(label: "User", name: "Testing") | |||
Neo4j::Http::Client.delete_node(node) | |||
``` | |||
|
|||
### Upsert and delete nodes in batch via UNWIND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I presume delete would be similar except Neo4j::Http::Client.delete_node(node, unwind: [...]
)
@@ -26,7 +28,9 @@ def upsert_node(node) | |||
results.first&.fetch("node") | |||
end | |||
|
|||
def delete_node(node) | |||
def delete_node(node, unwind: nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we instead create plural methods of these? So that unwind:
isn't an optional argument, but instead you're explicitly calling a method to do things in bulk.
@@ -26,7 +28,9 @@ def upsert_node(node) | |||
results.first&.fetch("node") | |||
end | |||
|
|||
def delete_node(node) | |||
def delete_node(node, unwind: nil) | |||
return delete_node_via_unwind(node, unwind) if unwind.present? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^^ This makes me thing - 100% we should, yes. I don't see the value in overriding delete_mode
, but maybe I'm missing it
we're moving away from neo4j so closing this |
JIRA story: https://doximity.atlassian.net/browse/MOFONETPROFILES-294
Overview
Use UNWIND strategy
Technical Information
This is somewhat different from upsert_node but it is conceptually still an upsert node operation with a different payload so I've opted to use a kwarg to support this.
The node is still required because we pull some important pieces off of this including the label and key name (primary key)
This is taken from https://medium.com/neo4j/5-tips-tricks-for-fast-batched-updates-of-graph-structures-with-neo4j-and-cypher-73c7f693c8cc