-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds support for multigraphs * Refactors `_is_edge_attr_match` * Filters relations by __label__ during `_lookup` * Bundles relation attributes together for lookup * Refactors and adds inline docs * Adds tests for multigraph support * Cleans up inline docs * Removes slicing list twice to avoid two copies in memory * Supports WHERE clause for relationships in multigraphs * Adds test for multigraph with WHERE clause on single edge * Accounts for WHERE with string node attributes in MultiDiGraphs * Unifies all unit tests to work with both DiGraphs and MultiDiGraphs * Completes multidigraph test for WHERE on node attribute * Supports logical OR for relationship matching * Adds tests for logical OR in MATCH for relationships * Implements aggregation functions * Removes unused code * Adds agg function results to `_return_requests` * Handles `None` values appropriately for MIN and MAX * Adds tests for agg functions and adjusts existing tests to new output * Adds examples page * Adds test for multiple agg functions * Removes commented code
- Loading branch information
Showing
4 changed files
with
296 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
|
||
## Multigraph | ||
|
||
```python | ||
from grandcypher import GrandCypher | ||
import networkx as nx | ||
|
||
host = nx.MultiDiGraph() | ||
host.add_node("a", name="Alice", age=25) | ||
host.add_node("b", name="Bob", age=30) | ||
host.add_edge("a", "b", __labels__={"paid"}, amount=12, date="12th June") | ||
host.add_edge("b", "a", __labels__={"paid"}, amount=6) | ||
host.add_edge("b", "a", __labels__={"paid"}, value=14) | ||
host.add_edge("a", "b", __labels__={"friends"}, years=9) | ||
host.add_edge("a", "b", __labels__={"paid"}, amount=40) | ||
|
||
qry = """ | ||
MATCH (n)-[r:paid]->(m) | ||
RETURN n.name, m.name, r.amount | ||
""" | ||
res = GrandCypher(host).run(qry) | ||
print(res) | ||
|
||
''' | ||
{ | ||
'n.name': ['Alice', 'Bob'], | ||
'm.name': ['Bob', 'Alice'], | ||
'r.amount': [{(0, 'paid'): 12, (1, 'friends'): None, (2, 'paid'): 40}, {(0, 'paid'): 6, (1, 'paid'): None}] | ||
} | ||
''' | ||
``` | ||
|
||
## Aggregation Functions | ||
|
||
```python | ||
from grandcypher import GrandCypher | ||
import networkx as nx | ||
|
||
host = nx.MultiDiGraph() | ||
host.add_node("a", name="Alice", age=25) | ||
host.add_node("b", name="Bob", age=30) | ||
host.add_edge("a", "b", __labels__={"paid"}, amount=12, date="12th June") | ||
host.add_edge("b", "a", __labels__={"paid"}, amount=6) | ||
host.add_edge("b", "a", __labels__={"paid"}, value=14) | ||
host.add_edge("a", "b", __labels__={"friends"}, years=9) | ||
host.add_edge("a", "b", __labels__={"paid"}, amount=40) | ||
|
||
qry = """ | ||
MATCH (n)-[r:paid]->(m) | ||
RETURN n.name, m.name, SUM(r.amount) | ||
""" | ||
res = GrandCypher(host).run(qry) | ||
print(res) | ||
|
||
''' | ||
{ | ||
'n.name': ['Alice', 'Bob'], | ||
'm.name': ['Bob', 'Alice'], | ||
'SUM(r.amount)': [{'paid': 52, 'friends': 0}, {'paid': 6}] | ||
} | ||
''' | ||
``` | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.