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

[15721] Implement Sequence in peloton #1292

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
30d48ac
finish part of parser; need to add handler function in create_executo…
HenryZhou0333 Mar 22, 2018
086b493
finish part of parser; need to add handler function in create_executo…
HenryZhou0333 Mar 22, 2018
59b85f6
Merge branch 'master' of https://github.com/HenryZhou0333/peloton
HenryZhou0333 Mar 22, 2018
282afb3
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Mar 27, 2018
28b702e
add postgresql parser test for sequences
HenryZhou0333 Mar 28, 2018
ddb3dd7
remove AS in sequencce
HenryZhou0333 Mar 28, 2018
26230e3
add exception for redefined parser
HenryZhou0333 Mar 28, 2018
b273056
finish compiling create sequence
HenryZhou0333 Mar 31, 2018
d90a649
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Mar 31, 2018
c1a4e1d
having issue with GetSequence()
HenryZhou0333 Apr 2, 2018
f8ec42a
add new GetSequence impl; fix BasicTest in sequence
HenryZhou0333 Apr 8, 2018
0d3521c
add tests for sequence
HenryZhou0333 Apr 10, 2018
8fe7d6c
fix merge conflict
HenryZhou0333 Apr 10, 2018
87680be
one step before submitting pr
HenryZhou0333 Apr 12, 2018
7d7955c
change way of update pg_sequence table in nextval
HenryZhou0333 Apr 12, 2018
503c89f
style fix
Apr 12, 2018
7762354
rename sequence test
HenryZhou0333 Apr 12, 2018
b340c86
Merge remote-tracking branch 'upstream/master'
HenryZhou0333 Apr 12, 2018
6897566
remove unnecessary file
HenryZhou0333 Apr 12, 2018
b8c7317
adding nextval & currval functions; comment out lock and nextval not …
danae-s Apr 14, 2018
d665c94
update pg_sequence after calling nextval; have seg fault in txn;
HenryZhou0333 Apr 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions src/catalog/abstract_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "executor/index_scan_executor.h"
#include "executor/insert_executor.h"
#include "executor/seq_scan_executor.h"
#include "executor/update_executor.h"
#include "executor/plan_executor.h"

#include "storage/database.h"
#include "storage/storage_manager.h"
Expand Down Expand Up @@ -272,5 +274,69 @@ void AbstractCatalog::AddIndex(const std::vector<oid_t> &key_attrs,
index_name.c_str(), (int)catalog_table_->GetOid());
}

/*@brief Update specific columns using index scan

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/*(space)brief
is probably better

* @param update_columns Columns to be updated
* @param update_values Values to be updated
* @param scan_values Value to be scaned (used in index scan)
* @param index_offset Offset of index for scan
* @return true if successfully executes
*/
bool AbstractCatalog::UpdateWithIndexScan(
std::vector<oid_t> update_columns, std::vector<type::Value> update_values,
std::vector<type::Value> scan_values, oid_t index_offset,
concurrency::TransactionContext *txn) {
if (txn == nullptr) throw CatalogException("Scan table requires transaction");

std::unique_ptr<executor::ExecutorContext> context(
new executor::ExecutorContext(txn));
// Construct index scan executor
auto index = catalog_table_->GetIndex(index_offset);
std::vector<oid_t> key_column_offsets =
index->GetMetadata()->GetKeySchema()->GetIndexedColumns();
PELOTON_ASSERT(scan_values.size() == key_column_offsets.size());
std::vector<ExpressionType> expr_types(scan_values.size(),
ExpressionType::COMPARE_EQUAL);
std::vector<expression::AbstractExpression *> runtime_keys;

planner::IndexScanPlan::IndexScanDesc index_scan_desc(
index, key_column_offsets, expr_types, scan_values, runtime_keys);

planner::IndexScanPlan index_scan_node(catalog_table_, nullptr,
update_columns, index_scan_desc);

executor::IndexScanExecutor index_scan_executor(&index_scan_node,
context.get());
// Construct update executor
TargetList target_list;
DirectMapList direct_map_list;

size_t column_count = catalog_table_->GetSchema()->GetColumnCount();
for (size_t col_itr = 0; col_itr < column_count; col_itr++) {
// Skip any column for update
if (std::find(std::begin(update_columns), std::end(update_columns),
col_itr) == std::end(update_columns)) {
direct_map_list.emplace_back(col_itr, std::make_pair(0, col_itr));
}
}

PELOTON_ASSERT(update_columns.size() == update_values.size());
for (size_t i = 0; i < update_values.size(); i++) {
planner::DerivedAttribute update_attribute{
new expression::ConstantValueExpression(update_values[i])};
target_list.emplace_back(update_columns[i], update_attribute);
}

std::unique_ptr<const planner::ProjectInfo> project_info(
new planner::ProjectInfo(std::move(target_list),
std::move(direct_map_list)));
planner::UpdatePlan update_node(catalog_table_, std::move(project_info));

executor::UpdateExecutor update_executor(&update_node, context.get());
update_executor.AddChild(&index_scan_executor);
// Execute
update_executor.Init();
return update_executor.Execute();
}

} // namespace catalog
} // namespace peloton
29 changes: 23 additions & 6 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
#include "catalog/table_catalog.h"
#include "catalog/table_metrics_catalog.h"
#include "catalog/trigger_catalog.h"
#include "catalog/sequence_catalog.h"
#include "concurrency/transaction_manager_factory.h"
#include "function/date_functions.h"
#include "function/decimal_functions.h"
#include "function/old_engine_string_functions.h"
#include "function/string_functions.h"
#include "function/timestamp_functions.h"
#include "index/index_factory.h"
#include "settings/settings_manager.h"
Expand Down Expand Up @@ -148,12 +150,13 @@ void Catalog::Bootstrap() {
DatabaseMetricsCatalog::GetInstance(txn);
TableMetricsCatalog::GetInstance(txn);
IndexMetricsCatalog::GetInstance(txn);
QueryMetricsCatalog::GetInstance(txn);
QueryMetricsCatalog::GetInstance(txn);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to keep spaces and lines to be consistent as before.

SettingsCatalog::GetInstance(txn);
TriggerCatalog::GetInstance(txn);
LanguageCatalog::GetInstance(txn);
ProcCatalog::GetInstance(txn);

SequenceCatalog::GetInstance(txn);

if (settings::SettingsManager::GetBool(settings::SettingId::brain)) {
QueryHistoryCatalog::GetInstance(txn);
}
Expand Down Expand Up @@ -1060,6 +1063,20 @@ void Catalog::InitializeFunctions() {
function::BuiltInFuncType{OperatorId::Like,
function::OldEngineStringFunctions::Like},
txn);
// Sequence
AddBuiltinFunction(
"nextval", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Nextval",
function::BuiltInFuncType{OperatorId::Nextval,
function::OldEngineStringFunctions::Nextval},
txn);
AddBuiltinFunction(
"currval", {type::TypeId::VARCHAR}, type::TypeId::INTEGER,
internal_lang, "Currval",
function::BuiltInFuncType{OperatorId::Currval,
function::OldEngineStringFunctions::Currval},
txn);


/**
* decimal functions
Expand Down Expand Up @@ -1106,28 +1123,28 @@ void Catalog::InitializeFunctions() {
* integer functions
*/
AddBuiltinFunction(
"abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
"abs", {type::TypeId::TINYINT}, type::TypeId::TINYINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::SMALLINT}, type::TypeId::SMALLINT,
"abs", {type::TypeId::SMALLINT}, type::TypeId::SMALLINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
"abs", {type::TypeId::INTEGER}, type::TypeId::INTEGER,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
txn);

AddBuiltinFunction(
"abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
"abs", {type::TypeId::BIGINT}, type::TypeId::BIGINT,
internal_lang, "Abs",
function::BuiltInFuncType{OperatorId::Abs,
function::DecimalFunctions::_Abs},
Expand Down
Loading