Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
eldenmoon committed Dec 20, 2024
1 parent 38b5a6a commit b38ca63
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
14 changes: 13 additions & 1 deletion be/src/olap/rowset_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,19 @@ void BaseRowsetBuilder::_build_current_tablet_schema(int64_t index_id,
indexes[i], ori_tablet_schema);
}
if (_tablet_schema->schema_version() > ori_tablet_schema.schema_version()) {
_tablet->update_max_version_schema(_tablet_schema);
// After schema change, should include extracted column
// For example: a table has two columns, k and v
// After adding a column v2, the schema version increases, max_version_schema needs to be updated.
// _tablet_schema includes k, v, and v2
// if v is a variant, need to add the columns decomposed from the v to the _tablet_schema.
if (_tablet_schema->num_variant_columns() > 0) {
TabletSchemaSPtr max_version_schema = std::make_shared<TabletSchema>();
max_version_schema->copy_from(*_tablet_schema);
max_version_schema->copy_extracted_columns(ori_tablet_schema);
_tablet->update_max_version_schema(max_version_schema);
} else {
_tablet->update_max_version_schema(_tablet_schema);
}
}

_tablet_schema->set_table_id(table_schema_param->table_id());
Expand Down
17 changes: 17 additions & 0 deletions be/src/olap/tablet_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,23 @@ bool TabletSchema::is_dropped_column(const TabletColumn& col) const {
return it == _field_name_to_index.end() || _cols[it->second]->unique_id() != col.unique_id();
}

void TabletSchema::copy_extracted_columns(const TabletSchema& src_schema) {
std::unordered_set<int32_t> variant_columns;
for (const auto& col : columns()) {
if (col->is_variant_type()) {
variant_columns.insert(col->unique_id());
}
}
for (const TabletColumnPtr& col : src_schema.columns()) {
if (col->is_extracted_column() && variant_columns.contains(col->parent_unique_id())) {
ColumnPB col_pb;
col->to_schema_pb(&col_pb);
TabletColumn new_col(col_pb);
append_column(new_col, ColumnType::VARIANT);
}
}
}

void TabletSchema::reserve_extracted_columns() {
for (auto it = _cols.begin(); it != _cols.end();) {
if (!(*it)->is_extracted_column()) {
Expand Down
3 changes: 3 additions & 0 deletions be/src/olap/tablet_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ class TabletSchema : public MetadataAdder<TabletSchema> {

bool is_dropped_column(const TabletColumn& col) const;

// copy extracted columns from src_schema
void copy_extracted_columns(const TabletSchema& src_schema);

// only reserve extracted columns
void reserve_extracted_columns();

Expand Down

0 comments on commit b38ca63

Please sign in to comment.