-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor and encapsulate for pre-decode (#201)
* refactor and encapsulate for pre-decode * fix bug when throw exception in RegionCFDataBase::insert * fix bug in TMTStorages::getAllStorage
- Loading branch information
Showing
4 changed files
with
151 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#include <sparsehash/dense_hash_map> | ||
#include <sparsehash/dense_hash_set> | ||
|
||
namespace DB | ||
{ | ||
|
||
namespace ErrorCodes | ||
{ | ||
extern const int LOGICAL_ERROR; | ||
} | ||
|
||
struct ColumnDataInfoMap | ||
{ | ||
using ColTypeInfo = std::tuple<MutableColumnPtr, NameAndTypePair, size_t>; | ||
using ColTypeInfoData = std::vector<ColTypeInfo>; | ||
|
||
ColumnDataInfoMap(const size_t cap, const ColumnID empty_id) | ||
{ | ||
column_data.reserve(cap); | ||
column_map.set_empty_key(empty_id); | ||
ori_cap = column_data.capacity(); | ||
} | ||
|
||
/// Notice: iterator of std::vector will invalid after the capacity changed, so !!! must set the capacity big enough | ||
void checkValid() const | ||
{ | ||
if (ori_cap != column_data.capacity()) | ||
throw Exception("ColumnDataInfoMap capacity changes", ErrorCodes::LOGICAL_ERROR); | ||
} | ||
|
||
void insert(const ColumnID col_id, MutableColumnPtr && ptr, NameAndTypePair && name_pair, size_t index, const size_t cap) | ||
{ | ||
column_data.emplace_back(std::move(ptr), std::move(name_pair), index); | ||
column_map.insert(std::make_pair(col_id, column_data.end() - 1)); | ||
getMutableColumnPtr(col_id)->reserve(cap); | ||
} | ||
|
||
MutableColumnPtr & getMutableColumnPtr(const ColumnID col_id) { return getMutableColumnPtr((*this)[col_id]); } | ||
static MutableColumnPtr & getMutableColumnPtr(ColTypeInfo & info) { return std::get<0>(info); } | ||
|
||
NameAndTypePair & getNameAndTypePair(const ColumnID col_id) { return getNameAndTypePair((*this)[col_id]); } | ||
static NameAndTypePair & getNameAndTypePair(ColTypeInfo & info) { return std::get<1>(info); } | ||
|
||
static size_t getIndex(const ColTypeInfo & info) { return std::get<2>(info); } | ||
|
||
ColTypeInfo & operator[](const ColumnID col_id) { return *column_map[col_id]; } | ||
|
||
private: | ||
ColTypeInfoData column_data; | ||
google::dense_hash_map<ColumnID, ColTypeInfoData::iterator> column_map; | ||
size_t ori_cap; | ||
}; | ||
|
||
struct DecodedRecordData | ||
{ | ||
DecodedRecordData(const size_t cap) | ||
{ | ||
additional_decoded_row.reserve(cap); | ||
ori_cap = additional_decoded_row.capacity(); | ||
} | ||
|
||
/// just like ColumnDataInfoMap::checkValid | ||
void checkValid() const | ||
{ | ||
if (ori_cap != additional_decoded_row.capacity()) | ||
throw Exception("DecodedRecordData capacity changes", ErrorCodes::LOGICAL_ERROR); | ||
} | ||
|
||
size_t size() const { return decoded_col_iter.size(); } | ||
|
||
void clear() | ||
{ | ||
additional_decoded_row.clear(); | ||
decoded_col_iter.clear(); | ||
} | ||
|
||
const DecodedRow::value_type & operator[](const size_t index) const { return *decoded_col_iter[index]; } | ||
|
||
template <class... _Args> | ||
void emplace_back(_Args &&... __args) | ||
{ | ||
additional_decoded_row.emplace_back(std::forward<_Args>(__args)...); | ||
decoded_col_iter.emplace_back(additional_decoded_row.cend() - 1); | ||
} | ||
|
||
void push_back(const DecodedRow::const_iterator & iter) { decoded_col_iter.push_back(iter); } | ||
|
||
private: | ||
DecodedRow additional_decoded_row; | ||
std::vector<DecodedRow::const_iterator> decoded_col_iter; | ||
size_t ori_cap; | ||
}; | ||
|
||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.