| 1 | /** | 
|---|---|
| 2 | * This file implements template methods of IColumn that depend on other types | 
| 3 | * we don't want to include. | 
| 4 | * Currently, this is only the scatterImpl method that depends on PODArray | 
| 5 | * implementation. | 
| 6 | */ | 
| 7 | |
| 8 | #pragma once | 
| 9 | |
| 10 | #include <Columns/IColumn.h> | 
| 11 | #include <Common/PODArray.h> | 
| 12 | |
| 13 | namespace DB | 
| 14 | { | 
| 15 | |
| 16 | template <typename Derived> | 
| 17 | std::vector<IColumn::MutablePtr> IColumn::scatterImpl(ColumnIndex num_columns, | 
| 18 | const Selector & selector) const | 
| 19 | { | 
| 20 | size_t num_rows = size(); | 
| 21 | |
| 22 | if (num_rows != selector.size()) | 
| 23 | throw Exception( | 
| 24 | "Size of selector: "+ std::to_string(selector.size()) + " doesn't match size of column: "+ std::to_string(num_rows), | 
| 25 | ErrorCodes::SIZES_OF_COLUMNS_DOESNT_MATCH); | 
| 26 | |
| 27 | std::vector<MutablePtr> columns(num_columns); | 
| 28 | for (auto & column : columns) | 
| 29 | column = cloneEmpty(); | 
| 30 | |
| 31 | { | 
| 32 | size_t reserve_size = num_rows * 1.1 / num_columns; /// 1.1 is just a guess. Better to use n-sigma rule. | 
| 33 | |
| 34 | if (reserve_size > 1) | 
| 35 | for (auto & column : columns) | 
| 36 | column->reserve(reserve_size); | 
| 37 | } | 
| 38 | |
| 39 | for (size_t i = 0; i < num_rows; ++i) | 
| 40 | static_cast<Derived &>(*columns[selector[i]]).insertFrom(*this, i); | 
| 41 | |
| 42 | return columns; | 
| 43 | } | 
| 44 | |
| 45 | } | 
| 46 | 
