From 8b31823a28d09ef0f60eddbd1f8f9556f3379ecf Mon Sep 17 00:00:00 2001 From: jimingquan Date: Mon, 18 Oct 2021 10:26:23 +0800 Subject: [PATCH] address comment --- src/graph/context/ast/QueryAstContext.h | 4 ++-- src/graph/planner/ngql/MaintainPlanner.cpp | 8 ++++---- src/graph/validator/MaintainValidator.cpp | 17 +++++++---------- src/graph/validator/MaintainValidator.h | 8 ++++---- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/graph/context/ast/QueryAstContext.h b/src/graph/context/ast/QueryAstContext.h index a1e09dab85c..b4fb5596fbc 100644 --- a/src/graph/context/ast/QueryAstContext.h +++ b/src/graph/context/ast/QueryAstContext.h @@ -157,12 +157,12 @@ struct FetchEdgesContext final : public AstContext { std::string inputVarName; }; -struct AlterContext final : public AstContext { +struct AlterSchemaContext final : public AstContext { std::vector schemaItems; meta::cpp2::SchemaProp schemaProps; }; -struct CreateContext final : public AstContext { +struct CreateSchemaContext final : public AstContext { bool ifNotExist{false}; std::string name; meta::cpp2::Schema schema; diff --git a/src/graph/planner/ngql/MaintainPlanner.cpp b/src/graph/planner/ngql/MaintainPlanner.cpp index 02d009e6432..2d3e92debe6 100644 --- a/src/graph/planner/ngql/MaintainPlanner.cpp +++ b/src/graph/planner/ngql/MaintainPlanner.cpp @@ -13,7 +13,7 @@ namespace nebula { namespace graph { StatusOr CreateTagPlanner::transform(AstContext* astCtx) { - auto createCtx = static_cast(astCtx); + auto createCtx = static_cast(astCtx); SubPlan plan; plan.root = plan.tail = CreateTag::make(createCtx->qctx, nullptr, @@ -24,7 +24,7 @@ StatusOr CreateTagPlanner::transform(AstContext* astCtx) { } StatusOr CreateEdgePlanner::transform(AstContext* astCtx) { - auto createCtx = static_cast(astCtx); + auto createCtx = static_cast(astCtx); SubPlan plan; plan.root = plan.tail = CreateEdge::make(createCtx->qctx, nullptr, @@ -35,7 +35,7 @@ StatusOr CreateEdgePlanner::transform(AstContext* astCtx) { } StatusOr AlterTagPlanner::transform(AstContext* astCtx) { - auto alterCtx = static_cast(astCtx); + auto alterCtx = static_cast(astCtx); auto qctx = alterCtx->qctx; auto name = *static_cast(alterCtx->sentence)->name(); SubPlan plan; @@ -49,7 +49,7 @@ StatusOr AlterTagPlanner::transform(AstContext* astCtx) { } StatusOr AlterEdgePlanner::transform(AstContext* astCtx) { - auto alterCtx = static_cast(astCtx); + auto alterCtx = static_cast(astCtx); auto qctx = alterCtx->qctx; auto name = *static_cast(alterCtx->sentence)->name(); SubPlan plan; diff --git a/src/graph/validator/MaintainValidator.cpp b/src/graph/validator/MaintainValidator.cpp index e463a2c01ba..a2bfeb595d1 100644 --- a/src/graph/validator/MaintainValidator.cpp +++ b/src/graph/validator/MaintainValidator.cpp @@ -70,10 +70,9 @@ static StatusOr> validateSchemaOpts( if (opType == meta::cpp2::AlterSchemaOp::DROP) { const auto &colNames = schemaOpt->columnNames(); for (auto &colName : colNames) { - if (uniqueColName.find(*colName) != uniqueColName.end()) { + if (!uniqueColName.emplace(*colName).second) { return Status::SemanticError("Duplicate column name `%s'", colName->c_str()); } - uniqueColName.emplace(*colName); meta::cpp2::ColumnDef column; column.name = *colName; schema.columns_ref().value().emplace_back(std::move(column)); @@ -81,10 +80,9 @@ static StatusOr> validateSchemaOpts( } else { const auto &specs = schemaOpt->columnSpecs(); for (auto &spec : specs) { - if (uniqueColName.find(*spec->name()) != uniqueColName.end()) { + if (!uniqueColName.emplace(*spec->name()).second) { return Status::SemanticError("Duplicate column name `%s'", spec->name()->c_str()); } - uniqueColName.emplace(*spec->name()); } NG_LOG_AND_RETURN_IF_ERROR(validateColumns(specs, schema)); } @@ -133,16 +131,15 @@ static Status checkColName(const std::vector specs) { std::unordered_set uniqueColName; for (const auto &spec : specs) { auto name = *spec->name(); - if (uniqueColName.find(name) != uniqueColName.end()) { + if (!uniqueColName.emplace(name).second) { return Status::SemanticError("Duplicate column name `%s'", name.c_str()); } - uniqueColName.emplace(name); } return Status::OK(); } Status CreateTagValidator::validateImpl() { - createCtx_ = getContext(); + createCtx_ = getContext(); auto sentence = static_cast(sentence_); createCtx_->ifNotExist = sentence->isIfNotExist(); auto name = *sentence->name(); @@ -165,7 +162,7 @@ Status CreateTagValidator::validateImpl() { } Status CreateEdgeValidator::validateImpl() { - createCtx_ = getContext(); + createCtx_ = getContext(); auto sentence = static_cast(sentence_); createCtx_->ifNotExist = sentence->isIfNotExist(); auto name = *sentence->name(); @@ -210,7 +207,7 @@ Status DescEdgeValidator::toPlan() { } Status AlterTagValidator::validateImpl() { - alterCtx_ = getContext(); + alterCtx_ = getContext(); auto sentence = static_cast(sentence_); auto schemaItems = validateSchemaOpts(sentence->getSchemaOpts()); NG_RETURN_IF_ERROR(schemaItems); @@ -222,7 +219,7 @@ Status AlterTagValidator::validateImpl() { } Status AlterEdgeValidator::validateImpl() { - alterCtx_ = getContext(); + alterCtx_ = getContext(); auto sentence = static_cast(sentence_); auto schemaItems = validateSchemaOpts(sentence->getSchemaOpts()); NG_RETURN_IF_ERROR(schemaItems); diff --git a/src/graph/validator/MaintainValidator.h b/src/graph/validator/MaintainValidator.h index c3d88fa8e2a..7b02a0a9fb9 100644 --- a/src/graph/validator/MaintainValidator.h +++ b/src/graph/validator/MaintainValidator.h @@ -24,7 +24,7 @@ class CreateTagValidator final : public Validator { private: Status validateImpl() override; - std::unique_ptr createCtx_; + std::unique_ptr createCtx_; }; class CreateEdgeValidator final : public Validator { @@ -36,7 +36,7 @@ class CreateEdgeValidator final : public Validator { private: Status validateImpl() override; - std::unique_ptr createCtx_; + std::unique_ptr createCtx_; }; class DescTagValidator final : public Validator { @@ -90,7 +90,7 @@ class AlterTagValidator final : public Validator { private: Status validateImpl() override; - std::unique_ptr alterCtx_; + std::unique_ptr alterCtx_; }; class AlterEdgeValidator final : public Validator { @@ -102,7 +102,7 @@ class AlterEdgeValidator final : public Validator { private: Status validateImpl() override; - std::unique_ptr alterCtx_; + std::unique_ptr alterCtx_; }; class ShowTagsValidator final : public Validator {