Skip to content

Commit

Permalink
Removed bug with rel2graph.neo4j.match_nodes and multiple set attribu…
Browse files Browse the repository at this point in the history
…te equalities, fixes #21
  • Loading branch information
jkminder committed Apr 8, 2024
1 parent 892b2aa commit a3e9b20
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ The library is built specifically for converting data into a [neo4j](https://neo
This library has been developed at the [Chair of Systems Design at ETH Zürich](https://www.sg.ethz.ch).

## Installation
If you have setup a private ssh key for your github, copy-paste the command below to install the latest version ([v1.3.2][latest_tag]):
If you have setup a private ssh key for your github, copy-paste the command below to install the latest version ([v1.3.3][latest_tag]):
```
pip install git+ssh://[email protected]/sg-dev/[email protected].2
pip install git+ssh://[email protected]/sg-dev/[email protected].3
```

If you don't have ssh set up, download the latest wheel [here][latest_wheel] and install the wheel with:
Expand Down Expand Up @@ -94,7 +94,7 @@ converter()
# Known issues
If you encounter a bug or an unexplainable behavior, please check the [known issues](https://github.com/sg-dev/rel2graph/labels/bug) list. If your issue is not found, submit a new one.

[latest_version]: v1.3.2
[latest_tag]: https://github.com/sg-dev/rel2graph/releases/tag/v1.3.2
[latest_wheel]: https://github.com/sg-dev/rel2graph/releases/download/v1.3.2/rel2graph-1.3.2-py3-none-any.whl
[latest_version]: v1.3.3
[latest_tag]: https://github.com/sg-dev/rel2graph/releases/tag/v1.3.3
[latest_wheel]: https://github.com/sg-dev/rel2graph/releases/download/v1.3.3/rel2graph-1.3.3-py3-none-any.whl
[wiki]: https://rel2graph.jkminder.ch/index.html
4 changes: 4 additions & 0 deletions rel2graph/neo4j/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ def match_nodes(session: Session, *labels: List[str], **properties: dict):
data.append(v)
flat_params.append(k)

if len(data) > 1:
data = [data]

unwind = "UNWIND $data as r" if len(data) > 0 else ""
clause = cypher_join(unwind, _match_clause('n', tuple(flat_params), "r"), "RETURN n, LABELS(n), ID(n)", data=data)
print(clause)
records = session.run(*clause).data()
# Convert to Node
out = []
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name = "rel2graph",
packages = find_packages(),
version = "1.3.2",
version = "1.3.3",
description = "Library for converting relational data into graph data (neo4j)",
author = "Julian Minder",
author_email = "[email protected]",
Expand Down
17 changes: 14 additions & 3 deletions tests/unit/neo4j/test_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def session():
try:
delete_all(session)
# generate test data
n1 = Node("test", "second", id=1, name="test1")
n2 = Node("test", id=2, name="test2")
n1 = Node("test", "second", id=1, name="test1", anotherattr="test")
n2 = Node("test", id=2, name="test2", anotherattr="test")
n3 = Node("anotherlabel", id=3, name="test3")

r1 = Relationship(n1, "to", n2, id=1)
r2 = Relationship(n1, "to", n3, id=2)
r2 = Relationship(n1, "to", n3, id=2, name="test")

graph = n1 | n2 | n3 | r1 | r2
create(graph, session)
Expand Down Expand Up @@ -74,6 +74,11 @@ def test_match_nodes(session):
assert(len(nodes) == 1)
assert(check_node(nodes, 1))

# match by two properties
nodes = match_nodes(session, name="test1", anotherattr="test")
assert(len(nodes) == 1)
assert(check_node(nodes, 1))

def test_match_relationships(session):
# match by type
rels = match_relationships(session, rel_type="to")
Expand All @@ -86,6 +91,11 @@ def test_match_relationships(session):
assert(len(rels) == 1)
assert(check_rel(rels, 1))

# match by multiple properties
rels = match_relationships(session, rel_type="to", id=1, name="test")
assert(len(rels) == 1)
assert(check_rel(rels, 1))

# match by from node
n1 = match_nodes(session, "test", id=1)[0]
rels = match_relationships(session, from_node=n1)
Expand All @@ -98,3 +108,4 @@ def test_match_relationships(session):
rels = match_relationships(session, to_node=n2)
assert(len(rels) == 1)
assert(check_rel(rels, 1))

0 comments on commit a3e9b20

Please sign in to comment.