@@ -21,8 +21,8 @@ namespace executor {
21
21
22
22
// Constructor for alter table executor
23
23
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) {}
26
26
27
27
// Initialize executor
28
28
// Nothing to initialize for now
@@ -36,17 +36,22 @@ bool AlterExecutor::DInit() {
36
36
bool AlterExecutor::DExecute () {
37
37
LOG_TRACE (" Executing Drop..." );
38
38
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 ();
43
42
result = RenameColumn (node, current_txn);
44
- } else if (plan_node_type == PlanNodeType::ALTER) {
45
- LOG_TRACE (" Will perform alter table operations" );
46
43
} 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
+ }
50
55
}
51
56
52
57
return result;
@@ -69,7 +74,27 @@ bool AlterExecutor::RenameColumn(
69
74
if (txn->GetResult () == ResultType::SUCCESS) {
70
75
LOG_TRACE (" Rename column succeeded!" );
71
76
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
73
98
} else {
74
99
LOG_TRACE (" Result is: %s" , ResultTypeToString (txn->GetResult ()).c_str ());
75
100
}
0 commit comments