From 8380d3694f85cc1040abe1c294e6f2899b4fb5d8 Mon Sep 17 00:00:00 2001 From: Teon Banek Date: Wed, 17 May 2017 11:06:26 +0200 Subject: [PATCH] Raise semantic error when redeclaring node in MERGE Summary: openCypher expects MERGE to behave like CREATE. As such, it shouldn't be allowed to refer to declared nodes, while providing labels and properties. Reviewers: florijan, mislav.bradac Reviewed By: mislav.bradac Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D373 --- src/query/frontend/semantic/symbol_generator.cpp | 3 ++- tests/unit/query_semantic.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/query/frontend/semantic/symbol_generator.cpp b/src/query/frontend/semantic/symbol_generator.cpp index 2dba945c4..4a788dc47 100644 --- a/src/query/frontend/semantic/symbol_generator.cpp +++ b/src/query/frontend/semantic/symbol_generator.cpp @@ -270,7 +270,8 @@ bool SymbolGenerator::PreVisit(NodeAtom &node_atom) { bool props_or_labels = !node_atom.properties_.empty() || !node_atom.labels_.empty(); const auto &node_name = node_atom.identifier_->name_; - if (scope_.in_create && props_or_labels && HasSymbol(node_name)) { + if ((scope_.in_create || scope_.in_merge) && props_or_labels && + HasSymbol(node_name)) { throw SemanticException( "Cannot create node '" + node_name + "' with labels or properties, because it is already declared."); diff --git a/tests/unit/query_semantic.cpp b/tests/unit/query_semantic.cpp index b1fd700ad..617e91823 100644 --- a/tests/unit/query_semantic.cpp +++ b/tests/unit/query_semantic.cpp @@ -840,4 +840,20 @@ TEST(TestSymbolGenerator, MatchReturnAsteriskNoUserVariables) { EXPECT_THROW(query->Accept(symbol_generator), SemanticException); } +TEST(TestSymbolGenerator, MatchMergeExpandLabel) { + // Test MATCH (n) MERGE (m) -[r :r]-> (n:label) + Dbms dbms; + auto dba = dbms.active(); + auto r_type = dba->edge_type("r"); + auto label = dba->label("label"); + AstTreeStorage storage; + auto query = QUERY( + MATCH(PATTERN(NODE("n"))), + MERGE(PATTERN(NODE("m"), EDGE("r", r_type, EdgeAtom::Direction::RIGHT), + NODE("n", label)))); + SymbolTable symbol_table; + SymbolGenerator symbol_generator(symbol_table); + EXPECT_THROW(query->Accept(symbol_generator), SemanticException); +} + } // namespace