-
Notifications
You must be signed in to change notification settings - Fork 156
existential pattern match #492
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
existential pattern match #492
Conversation
|
The accepted CIP is the relevant baseline for this PR. |
| """ | ||
| When executing query: | ||
| """ | ||
| MATCH (n) WHERE (n)-->() RETURN n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| MATCH (n) WHERE (n)-->() RETURN n | |
| MATCH (n) WHERE exists( (n)-->() ) RETURN n |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no confirmation yet, however:
- the CIP does not mention
exists( <pattern> ) size( <pattern> )gets deprecated because if this kind of ugly syntax ambiguity between parenthesized expressions and node patternsexists( <pattern> )suffers the same kind of ugly syntax ambiguity between parenthesized expressions and node patterns
Hence, it would be kind of odd to keep exists( <pattern> ). So, based on that thinking, it looks much more likely that is deprecated too and hence it seems smarter to not invest into exists( <pattern> ) any effort.
Further, assuming exists( <pattern> ) goes out like size( <pattern> ) does, the category pattern will on contain pattern comprehensions. That give us the possibility to spilt pattern comprehension into multiple feature. However, that can happen in separate PR at a different time. Just something to keep in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that size(<pattern>) fails on the openCypher grammar, when the <pattern> is a node pattern. I reckon exists(<pattern>) will fail, too. From viewpoint of the grammar both are simply FunctionInvocations, which only allow expressions as parameters. Expressions currently allow RelationshipsPatterns, but I assume that will go away, too.
Anyway, the practical consequence of this is that scenarios that test the failing of these functions on a pattern argument require a @skipGrammarCheck tag, otherwise the integrity check will complain:
the query of step `When executing query:` in line XX has either a syntax conforming to the grammar or the scenario has the @skipGrammarCheck tag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Given the state of the discussion on <pattern> and exist( <pattern> ) in expressions that I am observing, the best is probably to not touch pattern/Pattern1.feature either was for the time being.
Nevertheless, working on the existential subquery part in a separate existentialSubquery category is good. That is stable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
| """ | ||
| When executing query: | ||
| """ | ||
| MATCH (n), (m) WHERE (n)-->(m) RETURN n. m |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| MATCH (n), (m) WHERE (n)-->(m) RETURN n. m | |
| MATCH (n), (m) WHERE (n)-->(m) RETURN n, m |
| Scenario: [13] Fail on matching two nodes on a single undirected connection between them | ||
| Given any graph | ||
| When executing query: | ||
| """ | ||
| MATCH (n), (m) WHERE (n)--(m) RETURN n. m | ||
| """ | ||
| Then a SyntaxError should be raised at compile time: RequiresDirectedRelationship | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scenario should actually work, so I would change it to something like
| Scenario: [13] Fail on matching two nodes on a single undirected connection between them | |
| Given any graph | |
| When executing query: | |
| """ | |
| MATCH (n), (m) WHERE (n)--(m) RETURN n. m | |
| """ | |
| Then a SyntaxError should be raised at compile time: RequiresDirectedRelationship | |
| Scenario: [13] Fail on matching two nodes on a single undirected connection between them | |
| Given an empty graph | |
| And having executed: | |
| """ | |
| CREATE (a:A)-[:REL1]->(b:B), (b)-[:REL2]->(a), (a)-[:REL3]->(:C), (a)-[:REL1]->(:D) | |
| """ | |
| When executing query: | |
| """ | |
| MATCH (n), (m) WHERE (n)--(m) RETURN n, m | |
| """ | |
| Then the result should be, in any order: | |
| | n | m | | |
| | (:A) | (:B) | | |
| | (:B) | (:A) | | |
| | (:A) | (:C) | | |
| | (:A) | (:D) | | |
| | (:C) | (:A) | | |
| | (:D) | (:A) | | |
| And no side effects |
| Scenario: [10] Fail on introducing unbounded variable in pattern | ||
| Given any graph | ||
| When executing query: | ||
| """ | ||
| MATCH (n) WHERE (n)-->(m) RETURN n | ||
| """ | ||
| Then a SyntaxError should be raised at compile time: UndefinedVariable | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expand this scenario to an outline to cover more failing patterns:
| Scenario: [10] Fail on introducing unbounded variable in pattern | |
| Given any graph | |
| When executing query: | |
| """ | |
| MATCH (n) WHERE (n)-->(m) RETURN n | |
| """ | |
| Then a SyntaxError should be raised at compile time: UndefinedVariable | |
| Scenario Outline: [10] Fail on introducing unbounded variables in pattern | |
| Given any graph | |
| When executing query: | |
| """ | |
| MATCH (n) WHERE <pattern> RETURN n | |
| """ | |
| Then a SyntaxError should be raised at compile time: UndefinedVariable | |
| Examples: | |
| | pattern | | |
| | (a) | | |
| | (n)-->(a) | | |
| | (a)-->(n) | | |
| | (n)<--(a) | | |
| | (n)--(a) | | |
| | (n)-[r]->() | | |
| | ()-[r]->(n) | | |
| | (n)<-[r]-() | | |
| | (n)-[r]-() | | |
| | ()-[r]->() | | |
| | ()<-[r]-() | | |
| | ()-[r]-() | | |
| | (n)-[r:REL]->(a {num: 5}) | | |
| | (n)-[r:REL*0..2]->(a {num: 5}) | | |
| | (n)-[r:REL]->(:C)<-[s:REL]-(a {num: 5}) | |
| | n | m | | ||
| | (:D) | (:B) | | ||
| | (:B) | (:D) | | ||
| And no side effects |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this pattern expression is supposed to be only allowed in WHERE, I would add scenarios that check that is fails in other places.
I would also scenario showing that it is combinable with other predicts in WHERE.
| And no side effects | |
| And no side effects | |
| Scenario: [19] Using a negated existential pattern predicate | |
| Given an empty graph | |
| And having executed: | |
| """ | |
| CREATE (a:A)-[:REL1]->(b:B), (b)-[:REL2]->(a), (a)-[:REL3]->(:C), (a)-[:REL1]->(:D) | |
| """ | |
| When executing query: | |
| """ | |
| MATCH (n) WHERE NOT (n)-[:REL2]-() RETURN n | |
| """ | |
| Then the result should be, in any order: | |
| | n | | |
| | (:A) | | |
| And no side effects | |
| Scenario: [20] Using two existential pattern predicates in a conjunction | |
| Given an empty graph | |
| And having executed: | |
| """ | |
| CREATE (a:A)-[:REL1]->(b:B), (b)-[:REL2]->(a), (a)-[:REL3]->(:C), (a)-[:REL1]->(:D) | |
| """ | |
| When executing query: | |
| """ | |
| MATCH (n) WHERE (n)-[:REL1]-() AND (n)-[:REL3]-() RETURN n | |
| """ | |
| Then the result should be, in any order: | |
| | n | | |
| | (:A) | | |
| And no side effects | |
| Scenario: [21] Using two existential pattern predicates in a disjunction | |
| Given an empty graph | |
| And having executed: | |
| """ | |
| CREATE (a:A)-[:REL1]->(b:B), (b)-[:REL2]->(a), (a)-[:REL3]->(:C), (a)-[:REL1]->(:D) | |
| """ | |
| When executing query: | |
| """ | |
| MATCH (n) WHERE (n)-[:REL1]-() OR (n)-[:REL2]-() RETURN n | |
| """ | |
| Then the result should be, in any order: | |
| | n | | |
| | (:A) | | |
| | (:B) | | |
| And no side effects | |
| Scenario: [22] Fail on using pattern in RETURN projection | |
| Given any graph | |
| When executing query: | |
| """ | |
| MATCH (n) RETURN (n)-->() | |
| """ | |
| Then a SyntaxError should be raised at compile time: UnexpectedSyntax | |
| Scenario: [23] Fail on using pattern in WITH projection | |
| Given any graph | |
| When executing query: | |
| """ | |
| MATCH (n) WITH (n)-->() RETURN n | |
| """ | |
| Then a SyntaxError should be raised at compile time: UnexpectedSyntax |
|
Hi Dvir, for further work on this PR, I like to draw your attention to PR #493, which has update to the CIP cited above and should form the basis for this feature here. The CIP update is obviously not merged, yet. Nevertheless, I am relatively confident that it illustrates the main direction of things. It also something you may want to make your colleagues aware of. Comment welcome, of course. |
|
The CIP has been merged. Further, I think we should rename |
|
|
this query |
That is right and expected. It is a legacy functionality that evaluates a naked pattern to a list. This will be removed in due course of the usual deprecation cycles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest a number of changes that should make the build green and fix some inconsistent indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a more thorough review now. I have found a number of bugs and suggested fixes. With these done, the PR should be mergeable, I hope.
|
@AviAvni the PR has merge conflicts now. Please locally rebase the underlying branch onto a current master to draw out and fix the conflicts. Thanks. |
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
Co-authored-by: Hannes Voigt <[email protected]>
8439d3f to
1e12482
Compare
|
@hvub done |
No description provided.