2020-05-28 15:34:33 +00:00
|
|
|
#pragma once
|
|
|
|
#include <Parsers/IAST_fwd.h>
|
|
|
|
#include <Storages/DataDestinationType.h>
|
|
|
|
#include <Storages/ColumnsDescription.h>
|
2020-06-05 11:54:54 +00:00
|
|
|
#include <Storages/KeyDescription.h>
|
2020-05-28 15:34:33 +00:00
|
|
|
#include <Interpreters/ExpressionActions.h>
|
|
|
|
#include <Interpreters/AggregateDescription.h>
|
|
|
|
#include <Storages/TTLMode.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2020-05-29 10:56:04 +00:00
|
|
|
/// Assignment expression in TTL with GROUP BY
|
|
|
|
struct TTLAggregateDescription
|
2020-05-28 16:31:27 +00:00
|
|
|
{
|
2020-05-29 10:56:04 +00:00
|
|
|
/// Name of column in assignment
|
2020-05-28 16:31:27 +00:00
|
|
|
/// x = sum(y)
|
|
|
|
/// ^
|
|
|
|
String column_name;
|
|
|
|
|
2020-05-29 10:56:04 +00:00
|
|
|
/// Name of column on the right hand of the assignment
|
2020-05-28 16:31:27 +00:00
|
|
|
/// x = sum(y)
|
|
|
|
/// ^~~~~~^
|
|
|
|
String expression_result_column_name;
|
|
|
|
|
2020-05-29 10:56:04 +00:00
|
|
|
/// Expressions to calculate the value of assignment expression
|
2020-05-28 16:31:27 +00:00
|
|
|
ExpressionActionsPtr expression;
|
2020-06-12 14:32:47 +00:00
|
|
|
|
|
|
|
TTLAggregateDescription() = default;
|
|
|
|
TTLAggregateDescription(const TTLAggregateDescription & other);
|
|
|
|
TTLAggregateDescription & operator=(const TTLAggregateDescription & other);
|
2020-05-28 16:31:27 +00:00
|
|
|
};
|
|
|
|
|
2020-05-29 10:56:04 +00:00
|
|
|
using TTLAggregateDescriptions = std::vector<TTLAggregateDescription>;
|
2020-05-28 16:31:27 +00:00
|
|
|
|
2020-05-28 15:34:33 +00:00
|
|
|
/// Common struct for TTL record in storage
|
|
|
|
struct TTLDescription
|
|
|
|
{
|
|
|
|
TTLMode mode;
|
|
|
|
|
|
|
|
/// Expression part of TTL AST:
|
|
|
|
/// TTL d + INTERVAL 1 DAY
|
2020-05-28 16:31:27 +00:00
|
|
|
/// ^~~~~~~~~~~~~~~~~~~^
|
2020-05-28 15:34:33 +00:00
|
|
|
ASTPtr expression_ast;
|
|
|
|
|
2020-08-08 00:47:03 +00:00
|
|
|
/// Expression actions evaluated from AST
|
2020-05-28 15:34:33 +00:00
|
|
|
ExpressionActionsPtr expression;
|
|
|
|
|
|
|
|
/// Result column of this TTL expression
|
|
|
|
String result_column;
|
|
|
|
|
2020-05-28 16:31:27 +00:00
|
|
|
/// WHERE part in TTL expression
|
|
|
|
/// TTL ... WHERE x % 10 == 0 and y > 5
|
|
|
|
/// ^~~~~~~~~~~~~~~~~~~~~~^
|
2020-05-28 15:34:33 +00:00
|
|
|
ExpressionActionsPtr where_expression;
|
|
|
|
|
2020-05-28 16:31:27 +00:00
|
|
|
/// Name of result column from WHERE expression
|
2020-05-28 15:34:33 +00:00
|
|
|
String where_result_column;
|
|
|
|
|
2020-05-28 16:31:27 +00:00
|
|
|
/// Names of key columns in GROUP BY expression
|
|
|
|
/// TTL ... GROUP BY toDate(d), x SET ...
|
|
|
|
/// ^~~~~~~~~~~~^
|
2020-05-28 15:34:33 +00:00
|
|
|
Names group_by_keys;
|
|
|
|
|
2020-05-28 16:31:27 +00:00
|
|
|
/// SET parts of TTL expression
|
2020-05-29 10:56:04 +00:00
|
|
|
TTLAggregateDescriptions set_parts;
|
2020-05-28 16:31:27 +00:00
|
|
|
|
|
|
|
/// Aggregate descriptions for GROUP BY in TTL
|
2020-05-28 15:34:33 +00:00
|
|
|
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.
|
2020-06-05 11:54:54 +00:00
|
|
|
static TTLDescription getTTLFromAST(const ASTPtr & definition_ast, const ColumnsDescription & columns, const Context & context, const KeyDescription & primary_key);
|
2020-06-05 17:29:40 +00:00
|
|
|
|
|
|
|
TTLDescription() = default;
|
|
|
|
TTLDescription(const TTLDescription & other);
|
|
|
|
TTLDescription & operator=(const TTLDescription & other);
|
2020-05-28 15:34:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Mapping from column name to column TTL
|
|
|
|
using TTLColumnsDescription = std::unordered_map<String, TTLDescription>;
|
|
|
|
using TTLDescriptions = std::vector<TTLDescription>;
|
|
|
|
|
|
|
|
/// 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;
|
2020-06-05 17:29:40 +00:00
|
|
|
|
2020-07-08 23:05:56 +00:00
|
|
|
TTLTableDescription() = default;
|
|
|
|
TTLTableDescription(const TTLTableDescription & other);
|
|
|
|
TTLTableDescription & operator=(const TTLTableDescription & other);
|
|
|
|
|
2020-06-05 17:29:40 +00:00
|
|
|
static TTLTableDescription getTTLForTableFromAST(
|
|
|
|
const ASTPtr & definition_ast, const ColumnsDescription & columns, const Context & context, const KeyDescription & primary_key);
|
2020-05-28 15:34:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|