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

Aggregation functions (COUNT, SUM, MIN, MAX, AVG) #45

Merged
merged 25 commits into from
Jun 10, 2024

Conversation

jackboyla
Copy link
Contributor

Mentioned in #27 and #39 . Supports (COUNT, SUM, MIN, MAX, AVG).

There was also a small change that needed to be made for MultiDiGraphs, which should make it clearer which edge is being referred to in the results.

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

Added more tests, and an examples page 😄

@j6k4m8
Copy link
Member

j6k4m8 commented Jun 10, 2024

mind-blown-whoa

WOOHOOOOOO! This is so great @jackboyla! I'll review this asap!!

@j6k4m8
Copy link
Member

j6k4m8 commented Jun 10, 2024

Incredible — going to merge this and roll to PyPI today!! Thank you again @jackboyla!! Making some awesome contributions :)

@j6k4m8 j6k4m8 merged commit f1ca6f7 into aplbrain:master Jun 10, 2024
6 checks passed
@jackboyla jackboyla deleted the aggregation-functions branch June 10, 2024 16:21
@jackboyla
Copy link
Contributor Author

awesome! it’s a pleasure🤗

@j6k4m8 j6k4m8 mentioned this pull request Jun 10, 2024
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.

2 participants