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

Commit 1ce6ed0

Browse files
author
Dean Chen
committed
merge
2 parents 8cdea77 + d1c8437 commit 1ce6ed0

20 files changed

+340
-278
lines changed

src/binder/bind_node_visitor.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ void BindNodeVisitor::Visit(parser::TransactionStatement *) {}
190190
void BindNodeVisitor::Visit(parser::AlterTableStatement *node) {
191191
node->TryBindDatabaseName(default_database_name_);
192192
}
193-
void BindNodeVisitor::Visit(parser::RenameFuncStatement *node) {
194-
node->TryBindDatabaseName(default_database_name_);
195-
}
196193
void BindNodeVisitor::Visit(parser::AnalyzeStatement *node) {
197194
node->TryBindDatabaseName(default_database_name_);
198195
}

src/catalog/catalog.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,20 @@ ResultType Catalog::AddColumn(
838838
*/
839839

840840
ResultType Catalog::DropColumn(
841-
UNUSED_ATTRIBUTE const std::string &database_name,
842-
UNUSED_ATTRIBUTE const std::string &table_name,
843-
UNUSED_ATTRIBUTE const std::vector<std::string> &columns,
844-
UNUSED_ATTRIBUTE concurrency::TransactionContext *txn) {
845-
// TODO: perform DROP Operation
841+
const std::string &database_name,
842+
const std::string &table_name,
843+
const std::vector<std::string> &columns,
844+
concurrency::TransactionContext *txn) {
845+
try {
846+
oid_t table_oid = Catalog::GetInstance()
847+
->GetTableObject(database_name, table_name, txn)
848+
->GetTableOid();
849+
for (std::string name: columns) {
850+
catalog::ColumnCatalog::GetInstance()->DeleteColumn(table_oid, name, txn);
851+
}
852+
} catch(CatalogException &e){
853+
return ResultType::FAILURE;
854+
}
846855
return ResultType::SUCCESS;
847856
}
848857

src/executor/alter_executor.cpp

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ namespace executor {
2222
// Constructor for alter table executor
2323
AlterExecutor::AlterExecutor(const planner::AbstractPlan *node,
2424
ExecutorContext *executor_context)
25-
: AbstractExecutor(node, executor_context) {}
25+
: AbstractExecutor(node, executor_context),
26+
isAlter_(!reinterpret_cast<const planner::AlterPlan *>(node)->IsRename()) {}
2627

2728
// Initialize executor
2829
// Nothing to initialize for now
@@ -36,24 +37,29 @@ bool AlterExecutor::DInit() {
3637
bool AlterExecutor::DExecute() {
3738
LOG_TRACE("Executing Alter...");
3839
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) {
40+
if (!isAlter_) {
41+
const planner::AlterPlan &node = GetPlanNode<planner::AlterPlan>();
42+
auto current_txn = executor_context_->GetTransaction();
4343
result = RenameColumn(node, current_txn);
44-
} else if (plan_node_type == PlanNodeType::ALTER) {
45-
LOG_TRACE("Will perform alter table operations");
4644
} else {
47-
throw NotImplementedException(
48-
StringUtil::Format("Plan node type not supported, %s",
49-
PlanNodeTypeToString(plan_node_type).c_str()));
45+
const planner::AlterPlan &node = GetPlanNode<planner::AlterPlan>();
46+
auto current_txn = executor_context_->GetTransaction();
47+
AlterType type = node.GetAlterTableType();
48+
switch (type) {
49+
case AlterType::DROP:
50+
result = DropColumn(node, current_txn);
51+
break;
52+
default:
53+
throw NotImplementedException(StringUtil::Format(
54+
"Alter Type not supported, %s", AlterTypeToString(type).c_str()));
55+
}
5056
}
5157

5258
return result;
5359
}
5460

5561
bool AlterExecutor::RenameColumn(
56-
const peloton::planner::RenamePlan &node,
62+
const peloton::planner::AlterPlan &node,
5763
peloton::concurrency::TransactionContext *txn) {
5864
auto database_name = node.GetDatabaseName();
5965
auto table_name = node.GetTableName();
@@ -67,7 +73,28 @@ bool AlterExecutor::RenameColumn(
6773
if (txn->GetResult() == ResultType::SUCCESS) {
6874
LOG_TRACE("Rename column succeeded!");
6975

70-
// Add on succeed logic if necessary
76+
// TODO: Add on succeed logic if necessary
77+
executor_context_->num_processed = 1;
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
7198
executor_context_->num_processed = 1;
7299
} else {
73100
LOG_TRACE("Result is: %s", ResultTypeToString(txn->GetResult()).c_str());

src/executor/plan_executor.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,9 @@ executor::AbstractExecutor *BuildExecutorTree(
336336
child_executor =
337337
new executor::PopulateIndexExecutor(plan, executor_context);
338338
break;
339-
case PlanNodeType::RENAME:
340-
child_executor = new executor::AlterExecutor(plan, executor_context);
339+
case PlanNodeType::ALTER:
340+
child_executor =
341+
new executor::AlterExecutor(plan, executor_context);
341342
break;
342343
default:
343344
LOG_ERROR("Unsupported plan node type : %s",

src/include/binder/bind_node_visitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ class BindNodeVisitor : public SqlNodeVisitor {
6868
void Visit(parser::CopyStatement *) override;
6969
void Visit(parser::AnalyzeStatement *) override;
7070
void Visit(parser::AlterTableStatement *) override;
71-
void Visit(parser::RenameFuncStatement *) override;
7271

7372
void Visit(expression::CaseExpression *expr) override;
7473
void Visit(expression::SubqueryExpression *expr) override;

src/include/common/internal_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ std::ostream &operator<<(std::ostream &os, const DropType &type);
646646
enum class AlterType {
647647
INVALID = INVALID_TYPE_ID, // invalid alter type
648648
RENAME = 1, // rename table, column, database...
649+
ADD = 2,
650+
DROP = 3
649651
};
650652
std::string AlterTypeToString(AlterType type);
651653
AlterType StringToAlterType(const std::string &str);

src/include/common/sql_node_visitor.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ class CreateFunctionStatement;
2121
class InsertStatement;
2222
class DeleteStatement;
2323
class DropStatement;
24-
class RenameFuncStatement;
2524
class AlterTableStatement;
2625
class ExplainStatement;
2726
class PrepareStatement;
@@ -84,7 +83,6 @@ class SqlNodeVisitor {
8483
virtual void Visit(parser::CopyStatement *) {}
8584
virtual void Visit(parser::AnalyzeStatement *) {}
8685
virtual void Visit(parser::AlterTableStatement *) {}
87-
virtual void Visit(parser::RenameFuncStatement *) {}
8886
virtual void Visit(parser::ExplainStatement *){};
8987

9088
virtual void Visit(expression::ComparisonExpression *expr);

src/include/executor/alter_executor.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "concurrency/transaction_context.h"
1616
#include "executor/abstract_executor.h"
1717
#include "planner/alter_plan.h"
18-
#include "planner/rename_plan.h"
1918

2019
namespace peloton {
2120

@@ -42,8 +41,14 @@ class AlterExecutor : public AbstractExecutor {
4241

4342
bool DExecute();
4443

45-
bool RenameColumn(const planner::RenamePlan &node,
44+
bool RenameColumn(const planner::AlterPlan &node,
4645
concurrency::TransactionContext *txn);
46+
47+
bool DropColumn(const planner::AlterPlan &node,
48+
concurrency::TransactionContext *txn);
49+
50+
private:
51+
bool isAlter_;
4752
};
4853

4954
} // executor

src/include/optimizer/query_node_visitor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ class CopyStatement;
2929
class AnalyzeStatement;
3030
class VariableSetStatement;
3131
class JoinDefinition;
32-
class RenameFuncStatement;
3332
class AlterTableStatement;
3433
struct TableRef;
3534

src/include/optimizer/query_to_operator_transformer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class QueryToOperatorTransformer : public SqlNodeVisitor {
6363
void Visit(parser::UpdateStatement *op) override;
6464
void Visit(parser::CopyStatement *op) override;
6565
void Visit(parser::AnalyzeStatement *op) override;
66-
void Visit(parser::RenameFuncStatement *op) override;
6766
void Visit(parser::AlterTableStatement *op) override;
6867
void Visit(expression::ComparisonExpression *expr) override;
6968
void Visit(expression::OperatorExpression *expr) override;

0 commit comments

Comments
 (0)