Example #1
0
void CreateTable() {
  const oid_t col_count = state.column_count + 1;
  const bool is_inlined = true;

  // Create schema first
  std::vector<catalog::Column> columns;

  for (oid_t col_itr = 0; col_itr < col_count; col_itr++) {
    auto column =
        catalog::Column(VALUE_TYPE_INTEGER, GetTypeSize(VALUE_TYPE_INTEGER),
                        "" + std::to_string(col_itr), is_inlined);

    columns.push_back(column);
  }

  catalog::Schema *table_schema = new catalog::Schema(columns);
  std::string table_name("HYADAPTTABLE");

  /////////////////////////////////////////////////////////
  // Create table.
  /////////////////////////////////////////////////////////

  bool own_schema = true;
  bool adapt_table = true;
  sdbench_table.reset(storage::TableFactory::GetDataTable(
      INVALID_OID, INVALID_OID, table_schema, table_name,
      state.tuples_per_tilegroup, own_schema, adapt_table));

  // PRIMARY INDEXES
  for(int index_itr = 0; index_itr < state.index_count; index_itr++) {

    std::vector<oid_t> key_attrs;

    auto tuple_schema = sdbench_table->GetSchema();
    catalog::Schema *key_schema;
    index::IndexMetadata *index_metadata;
    bool unique;

    key_attrs = {0};
    key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs);
    key_schema->SetIndexedColumns(key_attrs);

    unique = true;

    index_metadata = new index::IndexMetadata(
        "primary_index",
        index_itr,
        INDEX_TYPE_SKIPLIST,
        INDEX_CONSTRAINT_TYPE_PRIMARY_KEY,
        tuple_schema,
        key_schema,
        unique);

    index::Index *pkey_index = index::IndexFactory::GetInstance(index_metadata);
    sdbench_table->AddIndex(pkey_index);

  }

}
Example #2
0
void CreateTable(std::unique_ptr<storage::DataTable> &hyadapt_table,
                 bool build_indexes) {
  const bool is_inlined = true;

  // Create schema first
  std::vector<catalog::Column> columns;

  for (oid_t col_itr = 0; col_itr < column_count; col_itr++) {
    auto column = catalog::Column(type::TypeId::INTEGER,
                                  type::Type::GetTypeSize(type::TypeId::INTEGER),
                                  std::to_string(col_itr), is_inlined);
    columns.push_back(column);
  }

  catalog::Schema *table_schema = new catalog::Schema(columns);
  std::string table_name("HYADAPT_TABLE");

  /////////////////////////////////////////////////////////
  // Create table.
  /////////////////////////////////////////////////////////

  bool own_schema = true;
  bool adapt_table = true;
  hyadapt_table.reset(storage::TableFactory::GetDataTable(
      INVALID_OID, INVALID_OID, table_schema, table_name, tuples_per_tile_group,
      own_schema, adapt_table));

  // PRIMARY INDEX
  if (build_indexes == true) {
    std::vector<oid_t> key_attrs;

    auto tuple_schema = hyadapt_table->GetSchema();
    catalog::Schema *key_schema;
    index::IndexMetadata *index_metadata;
    bool unique;

    key_attrs = {0};
    key_schema = catalog::Schema::CopySchema(tuple_schema, key_attrs);
    key_schema->SetIndexedColumns(key_attrs);
    unique = true;

    index_metadata = new index::IndexMetadata(
        "primary_index", 123, INVALID_OID, INVALID_OID, IndexType::BWTREE,
        IndexConstraintType::PRIMARY_KEY, tuple_schema, key_schema, key_attrs,
        unique);

    std::shared_ptr<index::Index> pkey_index(
        index::IndexFactory::GetIndex(index_metadata));

    hyadapt_table->AddIndex(pkey_index);
  }
}