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

Logical OR for relationship MATCH #44

Merged
merged 17 commits into from
May 24, 2024

Conversation

jackboyla
Copy link
Contributor

@jackboyla jackboyla commented May 22, 2024

supports MATCH (n)-[r:colleague|friend]->(m)
plus some tests for it

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_node("c", name="Christine", age=30)
host.add_node("d", name="Derek", age=57)
host.add_edge("a", "b", __labels__={"friend"}, years=1, friendly="very")
host.add_edge("b", "a", __labels__={"colleague"}, years=2)
host.add_edge("b", "a", __labels__={"mentor"}, years=4)
host.add_edge("b", "c", __labels__={"chef"}, years=12)
host.add_edge("d", "b", __labels__={"friend"}, years=1, friendly="mildly")

qry = """
MATCH (n)-[r:colleague|friend]->(m)
RETURN n.name, m.name, r.__labels__, r.years, r.friendly
"""
res = GrandCypher(host).run(qry)
print(res)

'''
{
    'n.name': ['Alice', 'Bob', 'Derek'], 
    'm.name': ['Bob', 'Alice', 'Bob'], 
    'r.__labels__': [
        {0: {'friend'}}, {0: {'colleague'}, 1: {'mentor'}}, {0: {'friend'}}
    ], 
    'r.years': [{0: 1}, {0: 2, 1: 4}, {0: 1}], 
    'r.friendly': [{0: 'very'}, {0: None, 1: None}, {0: 'mildly'}]
}
'''

@j6k4m8
Copy link
Member

j6k4m8 commented May 23, 2024

I can't quite tell for my phone but I'll look at this might need to be rebased on latest trunk?

this is so cool — I had no idea cypher could do this!

@jackboyla
Copy link
Contributor Author

you're right! I just rebased 😄 yeah it's kind of niche and not really necessary (could just use WHERE) but it's nice to have

grandcypher/test_queries.py Show resolved Hide resolved
@j6k4m8
Copy link
Member

j6k4m8 commented May 24, 2024

totally, this is super nice to have! and the closer we can get to feature parity with the cypher spec the better, imo! every feature is great :)

@j6k4m8 j6k4m8 merged commit f6f4beb into aplbrain:master May 24, 2024
6 checks passed
@jackboyla jackboyla deleted the logical-or-for-relationship-match branch May 24, 2024 13:16
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