Skip to content

Commit

Permalink
Merge master and cleanup for issue cmu-db#1398
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaito7 committed Jun 28, 2018
2 parents 3a0d85a + d22bd24 commit 0657985
Show file tree
Hide file tree
Showing 133 changed files with 4,692 additions and 3,247 deletions.
2 changes: 1 addition & 1 deletion src/binder/bind_node_visitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ void BindNodeVisitor::Visit(parser::AnalyzeStatement *node) {
void BindNodeVisitor::Visit(expression::TupleValueExpression *expr) {
if (!expr->GetIsBound()) {
std::tuple<oid_t, oid_t, oid_t> col_pos_tuple;
std::shared_ptr<catalog::TableCatalogObject> table_obj = nullptr;
std::shared_ptr<catalog::TableCatalogEntry> table_obj = nullptr;
type::TypeId value_type;
int depth = -1;

Expand Down
16 changes: 9 additions & 7 deletions src/binder/binder_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ void BinderContext::AddRegularTable(const std::string db_name,
const std::string table_alias,
concurrency::TransactionContext *txn) {
// using catalog object to retrieve meta-data
auto table_object = catalog::Catalog::GetInstance()->GetTableObject(
db_name, schema_name, table_name, txn);
auto table_object = catalog::Catalog::GetInstance()->GetTableCatalogEntry(txn,
db_name,
schema_name,
table_name);

if (regular_table_alias_map_.find(table_alias) !=
regular_table_alias_map_.end() ||
Expand Down Expand Up @@ -79,9 +81,9 @@ void BinderContext::AddNestedTable(

bool BinderContext::GetColumnPosTuple(
const std::string &col_name,
std::shared_ptr<catalog::TableCatalogObject> table_obj,
std::shared_ptr<catalog::TableCatalogEntry> table_obj,
std::tuple<oid_t, oid_t, oid_t> &col_pos_tuple, type::TypeId &value_type) {
auto column_object = table_obj->GetColumnObject(col_name);
auto column_object = table_obj->GetColumnCatalogEntry(col_name);
if (column_object == nullptr) {
return false;
}
Expand Down Expand Up @@ -138,7 +140,7 @@ bool BinderContext::GetColumnPosTuple(

bool BinderContext::GetRegularTableObj(
std::shared_ptr<BinderContext> current_context, std::string &alias,
std::shared_ptr<catalog::TableCatalogObject> &table_obj, int &depth) {
std::shared_ptr<catalog::TableCatalogEntry> &table_obj, int &depth) {
while (current_context != nullptr) {
auto iter = current_context->regular_table_alias_map_.find(alias);
if (iter != current_context->regular_table_alias_map_.end()) {
Expand Down Expand Up @@ -174,9 +176,9 @@ void BinderContext::GenerateAllColumnExpressions(
std::vector<std::unique_ptr<expression::AbstractExpression>> &exprs) {
for (auto &entry : regular_table_alias_map_) {
auto &table_obj = entry.second;
auto col_cnt = table_obj->GetColumnObjects().size();
auto col_cnt = table_obj->GetColumnCatalogEntries().size();
for (size_t i = 0; i < col_cnt; i++) {
auto col_obj = table_obj->GetColumnObject(i);
auto col_obj = table_obj->GetColumnCatalogEntry(i);
auto tv_expr = new expression::TupleValueExpression(
std::string(col_obj->GetColumnName()), std::string(entry.first));
tv_expr->SetValueType(col_obj->GetColumnType());
Expand Down
7 changes: 5 additions & 2 deletions src/brain/query_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ void QueryLogger::LogQuery(std::string query_string, uint64_t timestamp) {

// Log query + fingerprint
auto &query_history_catalog = catalog::QueryHistoryCatalog::GetInstance();
query_history_catalog.InsertQueryHistory(
query_string, fingerprint.GetFingerprint(), timestamp, nullptr, txn);
query_history_catalog.InsertQueryHistory(txn,
query_string,
fingerprint.GetFingerprint(),
timestamp,
nullptr);

// We're done
txn_manager.CommitTransaction(txn);
Expand Down
62 changes: 34 additions & 28 deletions src/catalog/abstract_catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@
namespace peloton {
namespace catalog {

AbstractCatalog::AbstractCatalog(oid_t catalog_table_oid,
std::string catalog_table_name,
AbstractCatalog::AbstractCatalog(storage::Database *pg_catalog,
catalog::Schema *catalog_table_schema,
storage::Database *pg_catalog) {
oid_t catalog_table_oid,
std::string catalog_table_name) {
// set database_oid
database_oid = pg_catalog->GetOid();
database_oid_ = pg_catalog->GetOid();
// Create catalog_table_
catalog_table_ = storage::TableFactory::GetDataTable(
database_oid, catalog_table_oid, catalog_table_schema, catalog_table_name,
database_oid_, catalog_table_oid, catalog_table_schema, catalog_table_name,
DEFAULT_TUPLES_PER_TILEGROUP, true, false, true);
// Add catalog_table_ into pg_catalog database
pg_catalog->AddTable(catalog_table_, true);
}

AbstractCatalog::AbstractCatalog(const std::string &catalog_table_ddl,
concurrency::TransactionContext *txn) {
AbstractCatalog::AbstractCatalog(concurrency::TransactionContext *txn,
const std::string &catalog_table_ddl) {
// Execute create catalog table
auto &peloton_parser = parser::PostgresParser::GetInstance();
std::unique_ptr<executor::ExecutorContext> context(
Expand All @@ -74,17 +74,19 @@ AbstractCatalog::AbstractCatalog(const std::string &catalog_table_ddl,
executor.Execute();

// get catalog table oid
auto catalog_table_object = Catalog::GetInstance()->GetTableObject(
create_plan->GetDatabaseName(), create_plan->GetSchemaName(),
create_plan->GetTableName(), txn);
auto catalog_table_object =
Catalog::GetInstance()->GetTableCatalogEntry(txn,
create_plan->GetDatabaseName(),
create_plan->GetSchemaName(),
create_plan->GetTableName());

// set catalog_table_
try {
catalog_table_ = storage::StorageManager::GetInstance()->GetTableWithOid(
catalog_table_object->GetDatabaseOid(),
catalog_table_object->GetTableOid());
// set database_oid
database_oid = catalog_table_object->GetDatabaseOid();
database_oid_ = catalog_table_object->GetDatabaseOid();
} catch (CatalogException &e) {
LOG_TRACE("Can't find table %d! Return false",
catalog_table_object->GetTableOid());
Expand All @@ -96,8 +98,8 @@ AbstractCatalog::AbstractCatalog(const std::string &catalog_table_ddl,
* @param txn TransactionContext
* @return Whether insertion is Successful
*/
bool AbstractCatalog::InsertTuple(std::unique_ptr<storage::Tuple> tuple,
concurrency::TransactionContext *txn) {
bool AbstractCatalog::InsertTuple(concurrency::TransactionContext *txn,
std::unique_ptr<storage::Tuple> tuple) {
if (txn == nullptr)
throw CatalogException("Insert tuple requires transaction");

Expand Down Expand Up @@ -136,9 +138,9 @@ bool AbstractCatalog::InsertTuple(std::unique_ptr<storage::Tuple> tuple,
* @param txn TransactionContext
* @return Whether deletion is Successful
*/
bool AbstractCatalog::DeleteWithIndexScan(
oid_t index_offset, std::vector<type::Value> values,
concurrency::TransactionContext *txn) {
bool AbstractCatalog::DeleteWithIndexScan(concurrency::TransactionContext *txn,
oid_t index_offset,
std::vector<type::Value> values) {
if (txn == nullptr)
throw CatalogException("Delete tuple requires transaction");

Expand Down Expand Up @@ -188,9 +190,10 @@ bool AbstractCatalog::DeleteWithIndexScan(
*/
std::unique_ptr<std::vector<std::unique_ptr<executor::LogicalTile>>>
AbstractCatalog::GetResultWithIndexScan(
std::vector<oid_t> column_offsets, oid_t index_offset,
std::vector<type::Value> values,
concurrency::TransactionContext *txn) const {
concurrency::TransactionContext *txn,
std::vector<oid_t> column_offsets,
oid_t index_offset,
std::vector<type::Value> values) const {
if (txn == nullptr) throw CatalogException("Scan table requires transaction");

// Index scan
Expand Down Expand Up @@ -237,9 +240,10 @@ AbstractCatalog::GetResultWithIndexScan(
* @return Unique pointer of vector of logical tiles
*/
std::unique_ptr<std::vector<std::unique_ptr<executor::LogicalTile>>>
AbstractCatalog::GetResultWithSeqScan(std::vector<oid_t> column_offsets,
expression::AbstractExpression *predicate,
concurrency::TransactionContext *txn) {
AbstractCatalog::GetResultWithSeqScan(
concurrency::TransactionContext *txn,
expression::AbstractExpression *predicate,
std::vector<oid_t> column_offsets) {
if (txn == nullptr) throw CatalogException("Scan table requires transaction");

// Sequential scan
Expand Down Expand Up @@ -271,8 +275,9 @@ AbstractCatalog::GetResultWithSeqScan(std::vector<oid_t> column_offsets,
* Note: Use catalog::Catalog::CreateIndex() if you can, only ColumnCatalog and
* IndexCatalog should need this
*/
void AbstractCatalog::AddIndex(const std::vector<oid_t> &key_attrs,
oid_t index_oid, const std::string &index_name,
void AbstractCatalog::AddIndex(const std::string &index_name,
oid_t index_oid,
const std::vector<oid_t> &key_attrs,
IndexConstraintType index_constraint) {
auto schema = catalog_table_->GetSchema();
auto key_schema = catalog::Schema::CopySchema(schema, key_attrs);
Expand Down Expand Up @@ -306,10 +311,11 @@ void AbstractCatalog::AddIndex(const std::vector<oid_t> &key_attrs,
* @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) {
bool AbstractCatalog::UpdateWithIndexScan(concurrency::TransactionContext *txn,
oid_t index_offset,
std::vector<type::Value> scan_values,
std::vector<oid_t> update_columns,
std::vector<type::Value> update_values) {
if (txn == nullptr) throw CatalogException("Scan table requires transaction");

std::unique_ptr<executor::ExecutorContext> context(
Expand Down
Loading

0 comments on commit 0657985

Please sign in to comment.