minor fixes

This commit is contained in:
DavIvek 2024-03-01 14:38:18 +01:00
parent a2e21d0c86
commit ec3d487fab
3 changed files with 18 additions and 17 deletions

View File

@ -2662,8 +2662,8 @@ class SetLabels : public memgraph::query::Clause {
protected: protected:
SetLabels(Identifier *identifier, const std::vector<std::variant<LabelIx, Expression *>> &labels) SetLabels(Identifier *identifier, const std::vector<std::variant<LabelIx, Expression *>> &labels)
: identifier_(identifier), labels_(labels) {} : identifier_(identifier), labels_(labels) {}
SetLabels(Identifier *identifier, std::vector<LabelIx> labels) : identifier_(identifier) { SetLabels(Identifier *identifier, const std::vector<LabelIx> &labels) : identifier_(identifier) {
for (auto &label : labels) { for (const auto &label : labels) {
labels_.emplace_back(label); labels_.emplace_back(label);
} }
} }
@ -2735,8 +2735,8 @@ class RemoveLabels : public memgraph::query::Clause {
protected: protected:
RemoveLabels(Identifier *identifier, const std::vector<std::variant<LabelIx, Expression *>> &labels) RemoveLabels(Identifier *identifier, const std::vector<std::variant<LabelIx, Expression *>> &labels)
: identifier_(identifier), labels_(labels) {} : identifier_(identifier), labels_(labels) {}
RemoveLabels(Identifier *identifier, std::vector<LabelIx> labels) : identifier_(identifier) { RemoveLabels(Identifier *identifier, const std::vector<LabelIx> &labels) : identifier_(identifier) {
for (auto &label : labels) { for (const auto &label : labels) {
labels_.emplace_back(label); labels_.emplace_back(label);
} }
} }

View File

@ -627,7 +627,7 @@ bool SymbolGenerator::PostVisit(Pattern &) {
} }
bool SymbolGenerator::PreVisit(NodeAtom &node_atom) { 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) { auto check_node_semantic = [&node_atom, &scope, this](const bool props_or_labels) {
const auto &node_name = node_atom.identifier_->name_; const auto &node_name = node_atom.identifier_->name_;
if ((scope.in_create || scope.in_merge) && props_or_labels && HasSymbol(node_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; 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 if (scope.in_create) { // you can use expressions with labels only in create
for (auto &label : node_atom.labels_) { for (auto &label : node_atom.labels_) {
if (auto *expression = std::get_if<Expression *>(&label)) { if (auto *expression = std::get_if<Expression *>(&label)) {
(*expression)->Accept(*this); (*expression)->Accept(*this);
}
} }
} }

View File

@ -278,7 +278,7 @@ bool CreateNode::CreateNodeCursor::Pull(Frame &frame, ExecutionContext &context)
if (input_cursor_->Pull(frame, context)) { if (input_cursor_->Pull(frame, context)) {
// we have to resolve the labels before we can check for permissions // we have to resolve the labels before we can check for permissions
std::vector<storage::LabelId> labels; std::vector<storage::LabelId> labels;
for (auto label : self_.node_info_.labels) { for (const auto &label : self_.node_info_.labels) {
if (const auto *label_atom = std::get_if<storage::LabelId>(&label)) { if (const auto *label_atom = std::get_if<storage::LabelId>(&label)) {
labels.emplace_back(*label_atom); labels.emplace_back(*label_atom);
} else { } 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, ExpressionEvaluator evaluator(&frame, context.symbol_table, context.evaluation_context, context.db_accessor,
storage::View::NEW); storage::View::NEW);
std::vector<storage::LabelId> labels; std::vector<storage::LabelId> labels;
for (auto label : self_.node_info_.labels) { for (const auto &label : self_.node_info_.labels) {
if (const auto *label_atom = std::get_if<storage::LabelId>(&label)) { if (const auto *label_atom = std::get_if<storage::LabelId>(&label)) {
labels.emplace_back(*label_atom); labels.emplace_back(*label_atom);
} else { } else {
@ -3177,10 +3177,10 @@ bool SetLabels::SetLabelsCursor::Pull(Frame &frame, ExecutionContext &context) {
if (!input_cursor_->Pull(frame, context)) return false; if (!input_cursor_->Pull(frame, context)) return false;
std::vector<storage::LabelId> labels; std::vector<storage::LabelId> labels;
for (const auto &label : self_.labels_) { for (const auto &label : self_.labels_) {
if (std::holds_alternative<storage::LabelId>(label)) { if (const auto *label_id = std::get_if<storage::LabelId>(&label)) {
labels.push_back(std::get<storage::LabelId>(label)); labels.emplace_back(*label_id);
} else { } else {
labels.push_back( labels.emplace_back(
context.db_accessor->NameToLabel(std::get<query::Expression *>(label)->Accept(evaluator).ValueString())); context.db_accessor->NameToLabel(std::get<query::Expression *>(label)->Accept(evaluator).ValueString()));
} }
} }
@ -3356,10 +3356,10 @@ bool RemoveLabels::RemoveLabelsCursor::Pull(Frame &frame, ExecutionContext &cont
if (!input_cursor_->Pull(frame, context)) return false; if (!input_cursor_->Pull(frame, context)) return false;
std::vector<storage::LabelId> labels; std::vector<storage::LabelId> labels;
for (const auto &label : self_.labels_) { for (const auto &label : self_.labels_) {
if (std::holds_alternative<storage::LabelId>(label)) { if (const auto *label_id = std::get_if<storage::LabelId>(&label)) {
labels.push_back(std::get<storage::LabelId>(label)); labels.emplace_back(*label_id);
} else { } else {
labels.push_back( labels.emplace_back(
context.db_accessor->NameToLabel(std::get<query::Expression *>(label)->Accept(evaluator).ValueString())); context.db_accessor->NameToLabel(std::get<query::Expression *>(label)->Accept(evaluator).ValueString()));
} }
} }