diff --git a/src/query/frontend/ast/ast.hpp b/src/query/frontend/ast/ast.hpp index 9a49fcb04..e251d5a22 100644 --- a/src/query/frontend/ast/ast.hpp +++ b/src/query/frontend/ast/ast.hpp @@ -2662,8 +2662,8 @@ class SetLabels : public memgraph::query::Clause { protected: SetLabels(Identifier *identifier, const std::vector> &labels) : identifier_(identifier), labels_(labels) {} - SetLabels(Identifier *identifier, std::vector labels) : identifier_(identifier) { - for (auto &label : labels) { + SetLabels(Identifier *identifier, const std::vector &labels) : identifier_(identifier) { + for (const auto &label : labels) { labels_.emplace_back(label); } } @@ -2735,8 +2735,8 @@ class RemoveLabels : public memgraph::query::Clause { protected: RemoveLabels(Identifier *identifier, const std::vector> &labels) : identifier_(identifier), labels_(labels) {} - RemoveLabels(Identifier *identifier, std::vector labels) : identifier_(identifier) { - for (auto &label : labels) { + RemoveLabels(Identifier *identifier, const std::vector &labels) : identifier_(identifier) { + for (const auto &label : labels) { labels_.emplace_back(label); } } diff --git a/src/query/frontend/semantic/symbol_generator.cpp b/src/query/frontend/semantic/symbol_generator.cpp index de1880a7d..89625aed2 100644 --- a/src/query/frontend/semantic/symbol_generator.cpp +++ b/src/query/frontend/semantic/symbol_generator.cpp @@ -627,7 +627,7 @@ bool SymbolGenerator::PostVisit(Pattern &) { } bool SymbolGenerator::PreVisit(NodeAtom &node_atom) { - auto &scope = scopes_.back(); // change this part of code + auto &scope = scopes_.back(); auto check_node_semantic = [&node_atom, &scope, this](const bool props_or_labels) { const auto &node_name = node_atom.identifier_->name_; if ((scope.in_create || scope.in_merge) && props_or_labels && HasSymbol(node_name)) { @@ -641,10 +641,11 @@ bool SymbolGenerator::PreVisit(NodeAtom &node_atom) { scope.in_node_atom = true; - // TODO: check if the node is in create scope, then no need to check for the expression since we don't allow it - for (auto &label : node_atom.labels_) { - if (auto *expression = std::get_if(&label)) { - (*expression)->Accept(*this); + if (scope.in_create) { // you can use expressions with labels only in create + for (auto &label : node_atom.labels_) { + if (auto *expression = std::get_if(&label)) { + (*expression)->Accept(*this); + } } } diff --git a/src/query/plan/operator.cpp b/src/query/plan/operator.cpp index 6aea0915e..f27a6c2ba 100644 --- a/src/query/plan/operator.cpp +++ b/src/query/plan/operator.cpp @@ -278,7 +278,7 @@ bool CreateNode::CreateNodeCursor::Pull(Frame &frame, ExecutionContext &context) if (input_cursor_->Pull(frame, context)) { // we have to resolve the labels before we can check for permissions std::vector labels; - for (auto label : self_.node_info_.labels) { + for (const auto &label : self_.node_info_.labels) { if (const auto *label_atom = std::get_if(&label)) { labels.emplace_back(*label_atom); } else { @@ -381,7 +381,7 @@ bool CreateExpand::CreateExpandCursor::Pull(Frame &frame, ExecutionContext &cont ExpressionEvaluator evaluator(&frame, context.symbol_table, context.evaluation_context, context.db_accessor, storage::View::NEW); std::vector labels; - for (auto label : self_.node_info_.labels) { + for (const auto &label : self_.node_info_.labels) { if (const auto *label_atom = std::get_if(&label)) { labels.emplace_back(*label_atom); } else { @@ -3177,10 +3177,10 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) { if (!input_cursor_->Pull(frame, context)) return false; std::vector labels; for (const auto &label : self_.labels_) { - if (std::holds_alternative(label)) { - labels.push_back(std::get(label)); + if (const auto *label_id = std::get_if(&label)) { + labels.emplace_back(*label_id); } else { - labels.push_back( + labels.emplace_back( context.db_accessor->NameToLabel(std::get(label)->Accept(evaluator).ValueString())); } } @@ -3356,10 +3356,10 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont if (!input_cursor_->Pull(frame, context)) return false; std::vector labels; for (const auto &label : self_.labels_) { - if (std::holds_alternative(label)) { - labels.push_back(std::get(label)); + if (const auto *label_id = std::get_if(&label)) { + labels.emplace_back(*label_id); } else { - labels.push_back( + labels.emplace_back( context.db_accessor->NameToLabel(std::get(label)->Accept(evaluator).ValueString())); } }