Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit d7465e3

Browse files
sxzh93Dingshilun
authored andcommitted
add drop column executor
1 parent f7af80f commit d7465e3

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

src/executor/alter_executor.cpp

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ namespace executor {
2121

2222
// Constructor for alter table executor
2323
AlterExecutor::AlterExecutor(const planner::AbstractPlan *node,
24-
ExecutorContext *executor_context)
25-
: AbstractExecutor(node, executor_context) {}
24+
ExecutorContext *executor_context, bool isAlter)
25+
: AbstractExecutor(node, executor_context), isAlter_(isAlter) {}
2626

2727
// Initialize executor
2828
// Nothing to initialize for now
@@ -36,17 +36,22 @@ bool AlterExecutor::DInit() {
3636
bool AlterExecutor::DExecute() {
3737
LOG_TRACE("Executing Drop...");
3838
bool result = false;
39-
const planner::RenamePlan &node = GetPlanNode<planner::RenamePlan>();
40-
auto current_txn = executor_context_->GetTransaction();
41-
PlanNodeType plan_node_type = node.GetPlanNodeType();
42-
if (plan_node_type == PlanNodeType::RENAME) {
39+
if (!isAlter_) {
40+
const planner::RenamePlan &node = GetPlanNode<planner::RenamePlan>();
41+
auto current_txn = executor_context_->GetTransaction();
4342
result = RenameColumn(node, current_txn);
44-
} else if (plan_node_type == PlanNodeType::ALTER) {
45-
LOG_TRACE("Will perform alter table operations");
4643
} else {
47-
throw NotImplementedException(
48-
StringUtil::Format("Plan node type not supported, %s",
49-
PlanNodeTypeToString(plan_node_type).c_str()));
44+
const planner::AlterPlan &node = GetPlanNode<planner::AlterPlan>();
45+
auto current_txn = executor_context_->GetTransaction();
46+
AlterType type = node.GetAlterTableType();
47+
switch (type) {
48+
case AlterType::DROP:
49+
result = DropColumn(node, current_txn);
50+
break;
51+
default:
52+
throw NotImplementedException(StringUtil::Format(
53+
"Alter Type not supported, %s", AlterTypeToString(type).c_str()));
54+
}
5055
}
5156

5257
return result;
@@ -69,7 +74,27 @@ bool AlterExecutor::RenameColumn(
6974
if (txn->GetResult() == ResultType::SUCCESS) {
7075
LOG_TRACE("Rename column succeeded!");
7176

72-
// Add on succeed logic if necessary
77+
// TODO Add on succeed logic if necessary
78+
} else {
79+
LOG_TRACE("Result is: %s", ResultTypeToString(txn->GetResult()).c_str());
80+
}
81+
return false;
82+
}
83+
84+
bool AlterExecutor::DropColumn(const peloton::planner::AlterPlan &node,
85+
peloton::concurrency::TransactionContext *txn) {
86+
auto database_name = node.GetDatabaseName();
87+
auto table_name = node.GetTableName();
88+
auto drop_columns = node.GetDroppedColumns();
89+
90+
ResultType result = catalog::Catalog::GetInstance()->DropColumn(
91+
database_name, table_name, drop_columns, txn);
92+
txn->SetResult(result);
93+
94+
if (txn->GetResult() == ResultType::SUCCESS) {
95+
LOG_TRACE("Drop column succeed!");
96+
97+
// TODO Add on succeed logic if necessary
7398
} else {
7499
LOG_TRACE("Result is: %s", ResultTypeToString(txn->GetResult()).c_str());
75100
}

src/executor/plan_executor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,12 @@ executor::AbstractExecutor *BuildExecutorTree(
337337
new executor::PopulateIndexExecutor(plan, executor_context);
338338
break;
339339
case PlanNodeType::RENAME:
340-
child_executor = new executor::AlterExecutor(plan, executor_context);
340+
child_executor =
341+
new executor::AlterExecutor(plan, executor_context, false);
342+
break;
343+
case PlanNodeType::ALTER:
344+
child_executor =
345+
new executor::AlterExecutor(plan, executor_context, true);
341346
break;
342347
default:
343348
LOG_ERROR("Unsupported plan node type : %s",

src/include/executor/alter_executor.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AlterExecutor : public AbstractExecutor {
3333
AlterExecutor &operator=(AlterExecutor &&) = delete;
3434

3535
AlterExecutor(const planner::AbstractPlan *node,
36-
ExecutorContext *executor_context);
36+
ExecutorContext *executor_context, bool isAlter);
3737

3838
~AlterExecutor() {}
3939

@@ -44,6 +44,12 @@ class AlterExecutor : public AbstractExecutor {
4444

4545
bool RenameColumn(const planner::RenamePlan &node,
4646
concurrency::TransactionContext *txn);
47+
48+
bool DropColumn(const planner::AlterPlan &node,
49+
concurrency::TransactionContext *txn);
50+
51+
private:
52+
bool isAlter_;
4753
};
4854

4955
} // executor

0 commit comments

Comments
 (0)