Navigation Menu

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

Fix that MERGE did not enforce relationship uniqueness. #10771

Merged
merged 2 commits into from Jan 12, 2018
Merged

Fix that MERGE did not enforce relationship uniqueness. #10771

merged 2 commits into from Jan 12, 2018

Conversation

sherfert
Copy link
Contributor

Add predicates to MERGE clauses, so that our addUniquenessPredicates rewriter is able to
add a uniqueness predicate.

@@ -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)
Copy link
Contributor

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)
}
Copy link
Contributor

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

Copy link
Contributor

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,
Copy link
Contributor

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

@craigtaverner craigtaverner merged commit 63cd31c into neo4j:3.1 Jan 12, 2018
@sherfert sherfert deleted the 3.1-merge-rel-uniqueness branch January 12, 2018 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants