#pragma once #include #include #include #include #include #include #include namespace DB { struct TTLSetPartDescription { /// Name of column in set part of ttl expression /// x = sum(y) /// ^ String column_name; /// Name of column on the right hand of the set part of TTL expression /// x = sum(y) /// ^~~~~~^ String expression_result_column_name; /// Expressions to calculate the value of set expression ExpressionActionsPtr expression; }; using TTLSetPartDescriptions = std::vector; /// Common struct for TTL record in storage struct TTLDescription { TTLMode mode; /// Expression part of TTL AST: /// TTL d + INTERVAL 1 DAY /// ^~~~~~~~~~~~~~~~~~~^ ASTPtr expression_ast; /// Expresion actions evaluated from AST ExpressionActionsPtr expression; /// Result column of this TTL expression String result_column; /// WHERE part in TTL expression /// TTL ... WHERE x % 10 == 0 and y > 5 /// ^~~~~~~~~~~~~~~~~~~~~~^ ExpressionActionsPtr where_expression; /// Name of result column from WHERE expression String where_result_column; /// Names of key columns in GROUP BY expression /// TTL ... GROUP BY toDate(d), x SET ... /// ^~~~~~~~~~~~^ Names group_by_keys; /// SET parts of TTL expression TTLSetPartDescriptions set_parts; /// Aggregate descriptions for GROUP BY in TTL AggregateDescriptions aggregate_descriptions; /// Destination type, only valid for table TTLs. /// For example DISK or VOLUME DataDestinationType destination_type; /// Name of destination disk or volume String destination_name; /// Parse TTL structure from definition. Able to parse both column and table /// TTLs. static TTLDescription getTTLFromAST(const ASTPtr & definition_ast, const ColumnsDescription & columns, const Context & context, const StorageMetadataKeyField & primary_key); }; /// Mapping from column name to column TTL using TTLColumnsDescription = std::unordered_map; using TTLDescriptions = std::vector; /// Common TTL for all table. Specified after defining the table columns. struct TTLTableDescription { /// Definition. Include all parts of TTL: /// TTL d + INTERVAL 1 day TO VOLUME 'disk1' /// ^~~~~~~~~~~~~~~definition~~~~~~~~~~~~~~~^ ASTPtr definition_ast; /// Rows removing TTL TTLDescription rows_ttl; /// Moving data TTL (to other disks or volumes) TTLDescriptions move_ttl; }; }