| 50 | } |
| 51 | |
| 52 | TTLTransform::TTLTransform( |
| 53 | const ContextPtr & context, |
| 54 | SharedHeader header_, |
| 55 | const MergeTreeData & storage_, |
| 56 | const StorageMetadataPtr & metadata_snapshot_, |
| 57 | const MergeTreeData::MutableDataPartPtr & data_part_, |
| 58 | const NamesAndTypesList & expired_columns_, |
| 59 | time_t current_time_, |
| 60 | bool force_) |
| 61 | : IAccumulatingTransform(header_, addExpiredColumnsToBlock(header_, expired_columns_)) |
| 62 | , data_part(data_part_) |
| 63 | , expired_columns(expired_columns_) |
| 64 | , log(getLogger(storage_.getLogName() + " (TTLTransform)")) |
| 65 | { |
| 66 | auto old_ttl_infos = data_part->ttl_infos; |
| 67 | |
| 68 | if (metadata_snapshot_->hasRowsTTL()) |
| 69 | { |
| 70 | const auto & rows_ttl = metadata_snapshot_->getRowsTTL(); |
| 71 | auto algorithm = std::make_unique<TTLDeleteAlgorithm>( |
| 72 | getExpressions(rows_ttl, subqueries_for_sets, context), rows_ttl, |
| 73 | old_ttl_infos.table_ttl, current_time_, force_); |
| 74 | |
| 75 | /// Skip all data if table ttl is expired for part |
| 76 | if (algorithm->isMaxTTLExpired() && !rows_ttl.where_expression_ast) |
| 77 | all_data_dropped = true; |
| 78 | |
| 79 | algorithms.emplace_back(std::move(algorithm)); |
| 80 | delete_algorithm = static_cast<const TTLDeleteAlgorithm *>(algorithms.back().get()); |
| 81 | } |
| 82 | |
| 83 | for (const auto & where_ttl : metadata_snapshot_->getRowsWhereTTLs()) |
| 84 | algorithms.emplace_back(std::make_unique<TTLDeleteAlgorithm>( |
| 85 | getExpressions(where_ttl, subqueries_for_sets, context), where_ttl, |
| 86 | old_ttl_infos.rows_where_ttl[where_ttl.result_column], current_time_, force_)); |
| 87 | |
| 88 | for (const auto & group_by_ttl : metadata_snapshot_->getGroupByTTLs()) |
| 89 | algorithms.emplace_back(std::make_unique<TTLAggregationAlgorithm>( |
| 90 | getExpressions(group_by_ttl, subqueries_for_sets, context), group_by_ttl, |
| 91 | old_ttl_infos.group_by_ttl[group_by_ttl.result_column], current_time_, force_, |
| 92 | getInputPort().getHeader(), storage_)); |
| 93 | |
| 94 | const auto & storage_columns = metadata_snapshot_->getColumns(); |
| 95 | const auto & column_defaults = storage_columns.getDefaults(); |
| 96 | |
| 97 | auto build_default_expr = [&](const String & name) |
| 98 | { |
| 99 | using Result = std::pair<ExpressionActionsPtr, String>; |
| 100 | auto it = column_defaults.find(name); |
| 101 | if (it == column_defaults.end()) |
| 102 | return Result{}; |
| 103 | const auto & column = storage_columns.get(name); |
| 104 | auto default_ast = it->second.expression->clone(); |
| 105 | default_ast = addTypeConversionToAST(std::move(default_ast), column.type->getName()); |
| 106 | auto syntax_result = TreeRewriter(storage_.getContext()).analyze(default_ast, storage_columns.getAll()); |
| 107 | auto actions = ExpressionAnalyzer{default_ast, syntax_result, storage_.getContext()}.getActions(true); |
| 108 | return Result{actions, default_ast->getColumnName()}; |
| 109 | }; |
nothing calls this directly
no test coverage detected