| 27 | } |
| 28 | |
| 29 | void TTLColumnAlgorithm::execute(Block & block) |
| 30 | { |
| 31 | if (!block) |
| 32 | return; |
| 33 | |
| 34 | /// If we read not all table columns. E.g. while mutation. |
| 35 | if (!block.has(column_name)) |
| 36 | return; |
| 37 | |
| 38 | /// Nothing to do |
| 39 | if (!isMinTTLExpired()) |
| 40 | return; |
| 41 | |
| 42 | /// Later drop full column |
| 43 | if (isMaxTTLExpired()) |
| 44 | return; |
| 45 | |
| 46 | auto default_column = executeExpressionAndGetColumn(default_expression, block, default_column_name); |
| 47 | if (default_column) |
| 48 | default_column = default_column->convertToFullColumnIfConst(); |
| 49 | |
| 50 | auto ttl_column = executeExpressionAndGetColumn(description.expression, block, description.result_column); |
| 51 | |
| 52 | auto & column_with_type = block.getByName(column_name); |
| 53 | const IColumn * values_column = column_with_type.column.get(); |
| 54 | MutableColumnPtr result_column = values_column->cloneEmpty(); |
| 55 | result_column->reserve(block.rows()); |
| 56 | |
| 57 | for (size_t i = 0; i < block.rows(); ++i) |
| 58 | { |
| 59 | UInt32 cur_ttl = getTimestampByIndex(ttl_column.get(), i); |
| 60 | if (isTTLExpired(cur_ttl)) |
| 61 | { |
| 62 | if (default_column) |
| 63 | result_column->insertFrom(*default_column, i); |
| 64 | else |
| 65 | result_column->insertDefault(); |
| 66 | } |
| 67 | else |
| 68 | { |
| 69 | new_ttl_info.update(cur_ttl); |
| 70 | is_fully_empty = false; |
| 71 | result_column->insertFrom(*values_column, i); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | column_with_type.column = std::move(result_column); |
| 76 | } |
| 77 | |
| 78 | void TTLColumnAlgorithm::finalize(const MutableDataPartPtr & data_part) const |
| 79 | { |
no test coverage detected