Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 11 additions & 4 deletions be/src/olap/delta_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,18 @@ void DeltaWriter::_build_current_tablet_schema(int64_t index_id,
const POlapTableSchemaParam& ptable_schema_param,
const TabletSchema& ori_tablet_schema) {
_tablet_schema->copy_from(ori_tablet_schema);
//new tablet schame if new table

// find the right index id
int i = 0;
for (; i < ptable_schema_param.indexes_size(); i++) {
if (ptable_schema_param.indexes(i).id() == index_id) break;
}

if (ptable_schema_param.indexes_size() > 0 &&
ptable_schema_param.indexes(0).columns_desc_size() != 0 &&
ptable_schema_param.indexes(0).columns_desc(0).unique_id() >= 0) {
_tablet_schema->build_current_tablet_schema(index_id, ptable_schema_param,
ptable_schema_param.indexes(i).columns_desc_size() != 0 &&
ptable_schema_param.indexes(i).columns_desc(0).unique_id() >= 0) {
_tablet_schema->build_current_tablet_schema(index_id, ptable_schema_param.version(),
ptable_schema_param.indexes(i),
ori_tablet_schema);
}
}
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/tablet_meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id
if (tcolumn.col_unique_id >= 0) {
unique_id = tcolumn.col_unique_id;
} else {
unique_id = col_ordinal_to_unique_id.at(col_ordinal++);
unique_id = col_ordinal_to_unique_id.at(col_ordinal);
}
col_ordinal++;
init_column_from_tcolumn(unique_id, tcolumn, column);

if (column->is_key()) {
Expand Down
42 changes: 19 additions & 23 deletions be/src/olap/tablet_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ std::string TabletSchema::to_key() const {
return pb.SerializeAsString();
}

void TabletSchema::build_current_tablet_schema(int64_t index_id,
const POlapTableSchemaParam& ptable_schema_param,
void TabletSchema::build_current_tablet_schema(int64_t index_id, int32_t version,
const POlapTableIndexSchema& index,
const TabletSchema& ori_tablet_schema) {
// copy from ori_tablet_schema
_keys_type = ori_tablet_schema.keys_type();
Expand All @@ -561,6 +561,7 @@ void TabletSchema::build_current_tablet_schema(int64_t index_id,
_sort_col_num = ori_tablet_schema.sort_col_num();

// copy from table_schema_param
_schema_version = version;
_num_columns = 0;
_num_key_columns = 0;
_num_null_columns = 0;
Expand All @@ -569,36 +570,31 @@ void TabletSchema::build_current_tablet_schema(int64_t index_id,
_field_name_to_index.clear();
_field_id_to_index.clear();

for (const POlapTableIndexSchema& index : ptable_schema_param.indexes()) {
if (index.id() == index_id) {
for (auto& pcolumn : index.columns_desc()) {
TabletColumn column;
column.init_from_pb(pcolumn);
if (column.is_key()) {
_num_key_columns++;
}
if (column.is_nullable()) {
_num_null_columns++;
}
if (column.is_bf_column()) {
has_bf_columns = true;
}
_field_name_to_index[column.name()] = _num_columns;
_field_id_to_index[column.unique_id()] = _num_columns;
_cols.emplace_back(std::move(column));
_num_columns++;
}
break;
for (auto& pcolumn : index.columns_desc()) {
TabletColumn column;
column.init_from_pb(pcolumn);
if (column.is_key()) {
_num_key_columns++;
}
if (column.is_nullable()) {
_num_null_columns++;
}
if (column.is_bf_column()) {
has_bf_columns = true;
}
_field_name_to_index[column.name()] = _num_columns;
_field_id_to_index[column.unique_id()] = _num_columns;
_cols.emplace_back(std::move(column));
_num_columns++;
}

if (has_bf_columns) {
_has_bf_fpp = true;
_bf_fpp = ori_tablet_schema.bloom_filter_fpp();
} else {
_has_bf_fpp = false;
_bf_fpp = BLOOM_FILTER_DEFAULT_FPP;
}
_schema_version = ptable_schema_param.version();
}

void TabletSchema::to_schema_pb(TabletSchemaPB* tablet_schema_pb) const {
Expand Down
6 changes: 3 additions & 3 deletions be/src/olap/tablet_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace vectorized {
class Block;
}

class POlapTableSchemaParam;
class POlapTableIndexSchema;

class TabletColumn {
public:
Expand Down Expand Up @@ -169,8 +169,8 @@ class TabletSchema {
const std::unordered_set<uint32_t>* tablet_columns_need_convert_null = nullptr) const;
vectorized::Block create_block() const;

void build_current_tablet_schema(int64_t index_id,
const POlapTableSchemaParam& ptable_schema_param,
void build_current_tablet_schema(int64_t index_id, int32_t version,
const POlapTableIndexSchema& index,
const TabletSchema& out_tablet_schema);

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,11 @@ private List<Column> checkAndPrepareMaterializedView(CreateMaterializedViewStmt
if (KeysType.UNIQUE_KEYS == olapTable.getKeysType() && olapTable.hasSequenceCol()) {
newMVColumns.add(new Column(olapTable.getSequenceCol()));
}

// set MV column unique id to Column.COLUMN_UNIQUE_ID_INIT_VALUE support old unique id rule.
newMVColumns.stream().forEach(column -> {
column.setUniqueId(Column.COLUMN_UNIQUE_ID_INIT_VALUE);
});
return newMVColumns;
}

Expand Down