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
Fix that MERGE did not enforce relationship uniqueness. #10771
Conversation
@@ -30,23 +30,23 @@ class NameMatchPatternElementTest extends CypherFunSuite { | |||
val original = parser.parse("MATCH (n)-[r:Foo]->() RETURN n") | |||
val expected = parser.parse("MATCH (n)-[r:Foo]->(` UNNAMED20`) RETURN n") | |||
|
|||
val result = original.rewrite(nameMatchPatternElements) | |||
val result = original.rewrite(nameMatchAndMergePatternElements) |
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 test class could also test MERGE clauses
graph.execute("CREATE (a) CREATE (a)-[:X]->(a)") | ||
val result = updateWithBothPlannersAndCompatibilityMode("MERGE (a)-[:X]->(b)-[:X]->(c) RETURN 42") | ||
assertStats(result, relationshipsCreated = 2, nodesCreated = 3) | ||
} |
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 the fix seems relevant to all predicates, perhaps we should have more tests:
- Test for relationship uniqueness without self-relationships
- Test for other predicates than relationship uniqueness
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've notice that the second case is already covered by the fact that Cypher does not allow explicit WHERE clauses for MERGE, and the implicit WHERE from in-lined Label and Property checks was already checked for separately, so the only predicate not covered was relationship uniqueness, which is good. I the meantime I have written a test for the first case.
@@ -47,7 +47,7 @@ class ASTRewriter(rewriterSequencer: (String) => RewriterStepSequencer, shouldEx | |||
enableCondition(containsNoReturnAll), | |||
foldConstants, | |||
ApplyRewriter("extractParameters", extractParameters), | |||
nameMatchPatternElements, | |||
nameMatchAndMergePatternElements, |
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.
There is already a nameUpdatingClauses Rewriter. That could be used here instead of changing nameMatchPatternElements
Add predicates to MERGE clauses, so that our addUniquenessPredicates rewriter is able to
add a uniqueness predicate.