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

Commit ed7a2a9

Browse files
DeanChensjDingshilun
authored andcommitted
Catalog for change column name
1 parent a2f73d9 commit ed7a2a9

File tree

2 files changed

+42
-44
lines changed

2 files changed

+42
-44
lines changed

src/catalog/catalog.cpp

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "catalog/table_metrics_catalog.h"
2727
#include "catalog/trigger_catalog.h"
2828
#include "concurrency/transaction_manager_factory.h"
29+
#include "executor/executor_context.h"
2930
#include "function/date_functions.h"
3031
#include "function/decimal_functions.h"
3132
#include "function/old_engine_string_functions.h"
@@ -34,6 +35,7 @@
3435
#include "settings/settings_manager.h"
3536
#include "storage/storage_manager.h"
3637
#include "storage/table_factory.h"
38+
#include "storage/tile.h"
3739
#include "type/ephemeral_pool.h"
3840

3941
namespace peloton {
@@ -148,12 +150,12 @@ void Catalog::Bootstrap() {
148150
DatabaseMetricsCatalog::GetInstance(txn);
149151
TableMetricsCatalog::GetInstance(txn);
150152
IndexMetricsCatalog::GetInstance(txn);
151-
QueryMetricsCatalog::GetInstance(txn);
153+
QueryMetricsCatalog::GetInstance(txn);
152154
SettingsCatalog::GetInstance(txn);
153155
TriggerCatalog::GetInstance(txn);
154156
LanguageCatalog::GetInstance(txn);
155157
ProcCatalog::GetInstance(txn);
156-
158+
157159
if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
158160
QueryHistoryCatalog::GetInstance(txn);
159161
}
@@ -614,18 +616,18 @@ ResultType Catalog::DropIndex(oid_t index_oid,
614616

615617
ResultType Catalog::DropIndex(const std::string &index_name,
616618
concurrency::TransactionContext *txn) {
617-
if(txn == nullptr) {
618-
throw CatalogException("Do not have transaction to drop index " +
619-
index_name);
620-
}
621-
auto index_object = catalog::IndexCatalog::GetInstance()->GetIndexObject(
622-
index_name, txn);
623-
if(index_object == nullptr) {
624-
throw CatalogException("Index name " + index_name + " cannot be found");
625-
}
626-
ResultType result = DropIndex(index_object->GetIndexOid(), txn);
619+
if (txn == nullptr) {
620+
throw CatalogException("Do not have transaction to drop index " +
621+
index_name);
622+
}
623+
auto index_object =
624+
catalog::IndexCatalog::GetInstance()->GetIndexObject(index_name, txn);
625+
if (index_object == nullptr) {
626+
throw CatalogException("Index name " + index_name + " cannot be found");
627+
}
628+
ResultType result = DropIndex(index_object->GetIndexOid(), txn);
627629

628-
return result;
630+
return result;
629631
}
630632

631633
//===--------------------------------------------------------------------===//
@@ -866,7 +868,7 @@ ResultType Catalog::ChangeColumnName(const std::string &database_name,
866868
table_oid, new_column.GetName(), columnId, new_column.GetOffset(),
867869
new_column.GetType(), new_column.IsInlined(),
868870
new_column.GetConstraints(), pool_.get(), txn);
869-
871+
870872
} catch (CatalogException &e) {
871873
return ResultType::FAILURE;
872874
}
@@ -1150,11 +1152,11 @@ void Catalog::InitializeFunctions() {
11501152
/**
11511153
* decimal functions
11521154
*/
1153-
AddBuiltinFunction(
1154-
"abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL, internal_lang,
1155-
"Abs", function::BuiltInFuncType{OperatorId::Abs,
1156-
function::DecimalFunctions::_Abs},
1157-
txn);
1155+
AddBuiltinFunction("abs", {type::TypeId::DECIMAL}, type::TypeId::DECIMAL,
1156+
internal_lang, "Abs",
1157+
function::BuiltInFuncType{
1158+
OperatorId::Abs, function::DecimalFunctions::_Abs},
1159+
txn);
11581160
AddBuiltinFunction(
11591161
"sqrt", {type::TypeId::TINYINT}, type::TypeId::DECIMAL, internal_lang,
11601162
"Sqrt", function::BuiltInFuncType{OperatorId::Sqrt,
@@ -1191,33 +1193,29 @@ void Catalog::InitializeFunctions() {
11911193
/**
11921194
* integer functions
11931195
*/
1194-
AddBuiltinFunction(
1195-
"abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
1196-
internal_lang, "Abs",
1197-
function::BuiltInFuncType{OperatorId::Abs,
1198-
function::DecimalFunctions::_Abs},
1199-
txn);
1196+
AddBuiltinFunction("abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
1197+
internal_lang, "Abs",
1198+
function::BuiltInFuncType{
1199+
OperatorId::Abs, function::DecimalFunctions::_Abs},
1200+
txn);
12001201

1201-
AddBuiltinFunction(
1202-
"abs", {type::TypeId::SMALLINT}, type::TypeId::SMALLINT,
1203-
internal_lang, "Abs",
1204-
function::BuiltInFuncType{OperatorId::Abs,
1205-
function::DecimalFunctions::_Abs},
1206-
txn);
1202+
AddBuiltinFunction("abs", {type::TypeId::SMALLINT},
1203+
type::TypeId::SMALLINT, internal_lang, "Abs",
1204+
function::BuiltInFuncType{
1205+
OperatorId::Abs, function::DecimalFunctions::_Abs},
1206+
txn);
12071207

1208-
AddBuiltinFunction(
1209-
"abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
1210-
internal_lang, "Abs",
1211-
function::BuiltInFuncType{OperatorId::Abs,
1212-
function::DecimalFunctions::_Abs},
1213-
txn);
1208+
AddBuiltinFunction("abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
1209+
internal_lang, "Abs",
1210+
function::BuiltInFuncType{
1211+
OperatorId::Abs, function::DecimalFunctions::_Abs},
1212+
txn);
12141213

1215-
AddBuiltinFunction(
1216-
"abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
1217-
internal_lang, "Abs",
1218-
function::BuiltInFuncType{OperatorId::Abs,
1219-
function::DecimalFunctions::_Abs},
1220-
txn);
1214+
AddBuiltinFunction("abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
1215+
internal_lang, "Abs",
1216+
function::BuiltInFuncType{
1217+
OperatorId::Abs, function::DecimalFunctions::_Abs},
1218+
txn);
12211219

12221220
AddBuiltinFunction(
12231221
"floor", {type::TypeId::INTEGER}, type::TypeId::DECIMAL,

src/include/catalog/schema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ class Schema : public Printable {
196196
}
197197

198198
// Get the default value for the column
199-
inline type::Value* GetDefaultValue(const oid_t column_id) const {
199+
inline type::Value *GetDefaultValue(const oid_t column_id) const {
200200
for (auto constraint : columns[column_id].GetConstraints()) {
201201
if (constraint.GetType() == ConstraintType::DEFAULT) {
202202
return constraint.getDefaultValue();

0 commit comments

Comments
 (0)