Skip to content
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

Conversation

bsimpson
Copy link
Contributor

@bsimpson bsimpson commented Oct 10, 2022

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.

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)

This is taken from https://medium.com/neo4j/5-tips-tricks-for-fast-batched-updates-of-graph-structures-with-neo4j-and-cypher-73c7f693c8cc

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)
Copy link

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?

Copy link

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?

Copy link
Contributor Author

@bsimpson bsimpson Oct 10, 2022

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
    }
  }
]

Copy link
Contributor Author

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
Copy link
Member

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)
Copy link
Member

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?
Copy link
Member

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

@tesshead-dox
Copy link
Contributor

we're moving away from neo4j so closing this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants