Skip to content

Commit

Permalink
Fix alter drop (#3036)
Browse files Browse the repository at this point in the history
* disable modify same col

* add test case

* refactor ddl

* fix pytest error

* address comment

Co-authored-by: Yee <[email protected]>
  • Loading branch information
nevermore3 and yixinglu authored Oct 19, 2021
1 parent 3747894 commit 32db50a
Show file tree
Hide file tree
Showing 17 changed files with 361 additions and 221 deletions.
11 changes: 11 additions & 0 deletions src/graph/context/ast/QueryAstContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ struct FetchEdgesContext final : public AstContext {
std::string inputVarName;
};

struct AlterSchemaContext final : public AstContext {
std::vector<meta::cpp2::AlterSchemaItem> schemaItems;
meta::cpp2::SchemaProp schemaProps;
};

struct CreateSchemaContext final : public AstContext {
bool ifNotExist{false};
std::string name;
meta::cpp2::Schema schema;
};

} // namespace graph
} // namespace nebula
#endif // GRAPH_CONTEXT_AST_QUERYASTCONTEXT_H_
1 change: 1 addition & 0 deletions src/graph/planner/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ nebula_add_library(
ngql/LookupPlanner.cpp
ngql/FetchVerticesPlanner.cpp
ngql/FetchEdgesPlanner.cpp
ngql/MaintainPlanner.cpp
)
21 changes: 21 additions & 0 deletions src/graph/planner/PlannersRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,38 @@
#include "graph/planner/ngql/FetchVerticesPlanner.h"
#include "graph/planner/ngql/GoPlanner.h"
#include "graph/planner/ngql/LookupPlanner.h"
#include "graph/planner/ngql/MaintainPlanner.h"
#include "graph/planner/ngql/PathPlanner.h"
#include "graph/planner/ngql/SubgraphPlanner.h"

namespace nebula {
namespace graph {

void PlannersRegister::registPlanners() {
registDDL();
registSequential();
registMatch();
}

void PlannersRegister::registDDL() {
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kAlterTag];
planners.emplace_back(&AlterTagPlanner::match, &AlterTagPlanner::make);
}
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kAlterEdge];
planners.emplace_back(&AlterEdgePlanner::match, &AlterEdgePlanner::make);
}
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kCreateTag];
planners.emplace_back(&CreateTagPlanner::match, &CreateTagPlanner::make);
}
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kCreateEdge];
planners.emplace_back(&CreateEdgePlanner::match, &CreateEdgePlanner::make);
}
}

void PlannersRegister::registSequential() {
{
auto& planners = Planner::plannersMap()[Sentence::Kind::kSequential];
Expand Down
1 change: 1 addition & 0 deletions src/graph/planner/PlannersRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PlannersRegister final {
static void registPlanners();

private:
static void registDDL();
static void registSequential();
static void registMatch();
};
Expand Down
66 changes: 66 additions & 0 deletions src/graph/planner/ngql/MaintainPlanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/

#include "graph/planner/ngql/MaintainPlanner.h"

#include "graph/context/ast/QueryAstContext.h"
#include "graph/planner/plan/Maintain.h"

namespace nebula {
namespace graph {

StatusOr<SubPlan> CreateTagPlanner::transform(AstContext* astCtx) {
auto createCtx = static_cast<CreateSchemaContext*>(astCtx);
SubPlan plan;
plan.root = plan.tail = CreateTag::make(createCtx->qctx,
nullptr,
std::move(createCtx->name),
std::move(createCtx->schema),
createCtx->ifNotExist);
return plan;
}

StatusOr<SubPlan> CreateEdgePlanner::transform(AstContext* astCtx) {
auto createCtx = static_cast<CreateSchemaContext*>(astCtx);
SubPlan plan;
plan.root = plan.tail = CreateEdge::make(createCtx->qctx,
nullptr,
std::move(createCtx->name),
std::move(createCtx->schema),
createCtx->ifNotExist);
return plan;
}

StatusOr<SubPlan> AlterTagPlanner::transform(AstContext* astCtx) {
auto alterCtx = static_cast<AlterSchemaContext*>(astCtx);
auto qctx = alterCtx->qctx;
auto name = *static_cast<const AlterTagSentence*>(alterCtx->sentence)->name();
SubPlan plan;
plan.root = plan.tail = AlterTag::make(qctx,
nullptr,
alterCtx->space.id,
std::move(name),
std::move(alterCtx->schemaItems),
std::move(alterCtx->schemaProps));
return plan;
}

StatusOr<SubPlan> AlterEdgePlanner::transform(AstContext* astCtx) {
auto alterCtx = static_cast<AlterSchemaContext*>(astCtx);
auto qctx = alterCtx->qctx;
auto name = *static_cast<const AlterEdgeSentence*>(alterCtx->sentence)->name();
SubPlan plan;
plan.root = plan.tail = AlterEdge::make(qctx,
nullptr,
alterCtx->space.id,
std::move(name),
std::move(alterCtx->schemaItems),
std::move(alterCtx->schemaProps));
return plan;
}

} // namespace graph
} // namespace nebula
62 changes: 62 additions & 0 deletions src/graph/planner/ngql/MaintainPlanner.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* Copyright (c) 2021 vesoft inc. All rights reserved.
*
* This source code is licensed under Apache 2.0 License,
* attached with Common Clause Condition 1.0, found in the LICENSES directory.
*/
#pragma once

#include "common/base/Base.h"
#include "graph/planner/Planner.h"
#include "graph/planner/plan/PlanNode.h"

namespace nebula {
namespace graph {

struct AstContext;

class CreateTagPlanner final : public Planner {
public:
static std::unique_ptr<CreateTagPlanner> make() {
return std::unique_ptr<CreateTagPlanner>(new CreateTagPlanner());
}
static bool match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kCreateTag;
}
StatusOr<SubPlan> transform(AstContext* astCtx) override;
};

class CreateEdgePlanner final : public Planner {
public:
static std::unique_ptr<CreateEdgePlanner> make() {
return std::unique_ptr<CreateEdgePlanner>(new CreateEdgePlanner());
}
static bool match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kCreateEdge;
}
StatusOr<SubPlan> transform(AstContext* astCtx) override;
};

class AlterTagPlanner final : public Planner {
public:
static std::unique_ptr<AlterTagPlanner> make() {
return std::unique_ptr<AlterTagPlanner>(new AlterTagPlanner());
}
static bool match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kAlterTag;
}
StatusOr<SubPlan> transform(AstContext* astCtx) override;
};

class AlterEdgePlanner final : public Planner {
public:
static std::unique_ptr<AlterEdgePlanner> make() {
return std::unique_ptr<AlterEdgePlanner>(new AlterEdgePlanner());
}
static bool match(AstContext* astCtx) {
return astCtx->sentence->kind() == Sentence::Kind::kAlterEdge;
}
StatusOr<SubPlan> transform(AstContext* astCtx) override;
};

} // namespace graph
} // namespace nebula
4 changes: 2 additions & 2 deletions src/graph/validator/FetchEdgesValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Status FetchEdgesValidator::validateEdgeKey() {
auto keys = sentence->keys()->keys();
edgeKeys.rows.reserve(keys.size());
for (const auto &key : keys) {
if (!evaluableExpr(key->srcid())) {
if (!ExpressionUtils::isEvaluableExpr(key->srcid())) {
return Status::SemanticError("`%s' is not evaluable.", key->srcid()->toString().c_str());
}
auto src = key->srcid()->eval(ctx);
Expand All @@ -116,7 +116,7 @@ Status FetchEdgesValidator::validateEdgeKey() {
}
auto ranking = key->rank();

if (!evaluableExpr(key->dstid())) {
if (!ExpressionUtils::isEvaluableExpr(key->dstid())) {
return Status::SemanticError("`%s' is not evaluable.", key->dstid()->toString().c_str());
}
auto dst = key->dstid()->eval(ctx);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/GroupByValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ Status GroupByValidator::groupClauseSemanticCheck() {
return false;
};
for (auto* expr : yieldCols_) {
if (evaluableExpr(expr)) {
if (ExpressionUtils::isEvaluableExpr(expr)) {
continue;
}
FindVisitor visitor(finder);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/validator/LookupValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ StatusOr<Expression*> LookupValidator::checkConstExpr(Expression* expr,
const std::string& prop,
const ExprKind kind) {
auto* pool = expr->getObjPool();
if (!evaluableExpr(expr)) {
if (!ExpressionUtils::isEvaluableExpr(expr)) {
return Status::SemanticError("'%s' is not an evaluable expression.", expr->toString().c_str());
}
auto schemaMgr = qctx_->schemaMng();
Expand Down
Loading

0 comments on commit 32db50a

Please sign in to comment.