From 3880ac47bd690b628629125af8593ff789d96420 Mon Sep 17 00:00:00 2001 From: kangkaisen Date: Thu, 22 Nov 2018 14:32:16 +0800 Subject: [PATCH] Add special add_column_statistics method for linked_schema_change --- be/src/olap/rowset.cpp | 25 ++++++++++++++++++++++++- be/src/olap/rowset.h | 3 +++ be/src/olap/schema_change.cpp | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/be/src/olap/rowset.cpp b/be/src/olap/rowset.cpp index 5b9074ed4081d1..240afd6681feed 100644 --- a/be/src/olap/rowset.cpp +++ b/be/src/olap/rowset.cpp @@ -198,6 +198,30 @@ void Rowset::delete_all_files() { } } +OLAPStatus Rowset::add_column_statistics_for_linked_schema_change( + const std::vector>& column_statistic_fields) { + //When add rollup table, the base table index maybe empty + if (column_statistic_fields.size() == 0) { + return OLAP_SUCCESS; + } + + //Should use _table->num_key_fields(), not column_statistic_fields.size() + //as rollup table num_key_fields will less than base table column_statistic_fields.size(). + //For LinkedSchemaChange, the rollup table keys order is the same as base table + for (size_t i = 0; i < _table->num_key_fields(); ++i) { + WrapperField* first = WrapperField::create(_table->tablet_schema()[i]); + DCHECK(first != NULL) << "failed to allocate memory for field: " << i; + first->copy(column_statistic_fields[i].first); + + WrapperField* second = WrapperField::create(_table->tablet_schema()[i]); + DCHECK(second != NULL) << "failed to allocate memory for field: " << i; + second->copy(column_statistic_fields[i].second); + + _column_statistics.push_back(std::make_pair(first, second)); + } + return OLAP_SUCCESS; +} + OLAPStatus Rowset::add_column_statistics( const std::vector>& column_statistic_fields) { DCHECK(column_statistic_fields.size() == _table->num_key_fields()); @@ -219,7 +243,6 @@ OLAPStatus Rowset::add_column_statistics( std::vector > &column_statistic_strings, std::vector &null_vec) { DCHECK(column_statistic_strings.size() == _table->num_key_fields()); - std::vector> column_statistics; for (size_t i = 0; i < column_statistic_strings.size(); ++i) { WrapperField* first = WrapperField::create(_table->tablet_schema()[i]); DCHECK(first != NULL) << "failed to allocate memory for field: " << i ; diff --git a/be/src/olap/rowset.h b/be/src/olap/rowset.h index 9c8b82ceb3785e..59d5450a492705 100644 --- a/be/src/olap/rowset.h +++ b/be/src/olap/rowset.h @@ -65,6 +65,9 @@ class Rowset { return _column_statistics.size() != 0; } + OLAPStatus add_column_statistics_for_linked_schema_change( + const std::vector>& column_statistic_fields); + OLAPStatus add_column_statistics( const std::vector>& column_statistic_fields); diff --git a/be/src/olap/schema_change.cpp b/be/src/olap/schema_change.cpp index f771f657333343..54d35170069699 100644 --- a/be/src/olap/schema_change.cpp +++ b/be/src/olap/schema_change.cpp @@ -715,7 +715,7 @@ bool LinkedSchemaChange::process(ColumnData* olap_data, Rowset* new_rowset) { new_rowset->set_empty(olap_data->empty()); new_rowset->set_num_segments(olap_data->olap_index()->num_segments()); - new_rowset->add_column_statistics(olap_data->olap_index()->get_column_statistics()); + new_rowset->add_column_statistics_for_linked_schema_change(olap_data->olap_index()->get_column_statistics()); if (OLAP_SUCCESS != new_rowset->load()) { OLAP_LOG_WARNING("fail to reload index. [table='%s' version='%d-%d']",