Compare commits

...

1 Commits

Author SHA1 Message Date
Andreja Tonev
d3838a1095 Allow query with a write subquery to omit RETURN 2024-03-04 16:57:39 +01:00
3 changed files with 27 additions and 0 deletions

View File

@ -2004,6 +2004,7 @@ class SingleQuery : public memgraph::query::Tree, public utils::Visitable<Hierar
}
std::vector<memgraph::query::Clause *> clauses_;
bool has_update{};
SingleQuery *Clone(AstStorage *storage) const override {
SingleQuery *object = storage->Create<SingleQuery>();
@ -2011,6 +2012,7 @@ class SingleQuery : public memgraph::query::Tree, public utils::Visitable<Hierar
for (auto i4 = 0; i4 < clauses_.size(); ++i4) {
object->clauses_[i4] = clauses_[i4] ? clauses_[i4]->Clone(storage) : nullptr;
}
object->has_update = has_update;
return object;
}

View File

@ -1150,6 +1150,17 @@ antlrcpp::Any CypherMainVisitor::visitSingleQuery(MemgraphCypher::SingleQueryCon
if (has_return) {
throw SemanticException("CALL can't be put after RETURN clause.");
}
const auto *single_query = call_subquery->cypher_query_->single_query_;
if (single_query) {
has_update |= single_query->has_update;
for (auto *cypher_union : call_subquery->cypher_query_->cypher_unions_) {
if (has_update) break;
const auto *single_query = cypher_union->single_query_;
if (single_query) {
has_update |= single_query->has_update;
}
}
}
} else if (utils::IsSubtype(clause_type, Unwind::kType)) {
check_write_procedure("UNWIND");
if (has_update || has_return) {
@ -1220,6 +1231,8 @@ antlrcpp::Any CypherMainVisitor::visitSingleQuery(MemgraphCypher::SingleQueryCon
}
}
}
single_query->has_update = has_update;
return single_query;
}

View File

@ -175,3 +175,15 @@ Feature: Create
CREATE (a:A) CREATE (a:B)
"""
Then an error should be raised
Scenario: CREATE via CALL:
When executing query:
"""
UNWIND range(1,10) as id
CALL {
WITH id
CREATE (b:B {prop: 1})
CREATE (b)-[:IN]->(z)
};
"""
Then the result should be empty