| 1 | #include <DataStreams/processConstants.h> |
| 2 | |
| 3 | namespace DB |
| 4 | { |
| 5 | |
| 6 | void removeConstantsFromBlock(Block & block) |
| 7 | { |
| 8 | size_t columns = block.columns(); |
| 9 | size_t i = 0; |
| 10 | while (i < columns) |
| 11 | { |
| 12 | if (block.getByPosition(i).column && isColumnConst(*block.getByPosition(i).column)) |
| 13 | { |
| 14 | block.erase(i); |
| 15 | --columns; |
| 16 | } |
| 17 | else |
| 18 | ++i; |
| 19 | } |
| 20 | } |
| 21 | |
| 22 | |
| 23 | void removeConstantsFromSortDescription(const Block & , SortDescription & description) |
| 24 | { |
| 25 | /// Note: This code is not correct if column description contains column numbers instead of column names. |
| 26 | /// Hopefully, everywhere where it is used, column description contains names. |
| 27 | description.erase(std::remove_if(description.begin(), description.end(), |
| 28 | [&](const SortColumnDescription & elem) |
| 29 | { |
| 30 | auto & column = !elem.column_name.empty() ? header.getByName(elem.column_name) |
| 31 | : header.safeGetByPosition(elem.column_number); |
| 32 | return column.column && isColumnConst(*column.column); |
| 33 | }), description.end()); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | void enrichBlockWithConstants(Block & block, const Block & ) |
| 38 | { |
| 39 | size_t rows = block.rows(); |
| 40 | size_t columns = header.columns(); |
| 41 | |
| 42 | for (size_t i = 0; i < columns; ++i) |
| 43 | { |
| 44 | const auto & col_type_name = header.getByPosition(i); |
| 45 | if (col_type_name.column && isColumnConst(*col_type_name.column)) |
| 46 | block.insert(i, {col_type_name.column->cloneResized(rows), col_type_name.type, col_type_name.name}); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |