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
This commit is contained in:
parent
30a4f40093
commit
8380d3694f
@ -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.");
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user