2020-12-25 14:52:46 +00:00
|
|
|
#include <DataStreams/TTLUpdateInfoAlgorithm.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
TTLUpdateInfoAlgorithm::TTLUpdateInfoAlgorithm(
|
2021-08-03 07:37:25 +00:00
|
|
|
const TTLDescription & description_,
|
2021-08-04 14:16:13 +00:00
|
|
|
const TTLUpdateField ttl_update_field_,
|
2021-08-03 07:37:25 +00:00
|
|
|
const String ttl_update_key_,
|
|
|
|
const TTLInfo & old_ttl_info_,
|
|
|
|
time_t current_time_,
|
|
|
|
bool force_)
|
2020-12-25 14:52:46 +00:00
|
|
|
: ITTLAlgorithm(description_, old_ttl_info_, current_time_, force_)
|
2021-08-04 14:16:13 +00:00
|
|
|
, ttl_update_field(ttl_update_field_)
|
2021-08-03 07:37:25 +00:00
|
|
|
, ttl_update_key(ttl_update_key_)
|
2020-12-25 14:52:46 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TTLUpdateInfoAlgorithm::execute(Block & block)
|
|
|
|
{
|
|
|
|
if (!block)
|
|
|
|
return;
|
|
|
|
|
2021-01-12 16:42:49 +00:00
|
|
|
auto ttl_column = executeExpressionAndGetColumn(description.expression, block, description.result_column);
|
2020-12-25 14:52:46 +00:00
|
|
|
for (size_t i = 0; i < block.rows(); ++i)
|
|
|
|
{
|
|
|
|
UInt32 cur_ttl = ITTLAlgorithm::getTimestampByIndex(ttl_column.get(), i);
|
|
|
|
new_ttl_info.update(cur_ttl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-30 04:27:15 +00:00
|
|
|
void TTLUpdateInfoAlgorithm::finalize(const MutableDataPartPtr & data_part) const
|
2020-12-25 14:52:46 +00:00
|
|
|
{
|
2021-08-04 14:16:13 +00:00
|
|
|
if (ttl_update_field == TTLUpdateField::RECOMPRESSION_TTL)
|
2021-07-30 04:27:15 +00:00
|
|
|
{
|
2021-08-03 07:37:25 +00:00
|
|
|
data_part->ttl_infos.recompression_ttl[ttl_update_key] = new_ttl_info;
|
2021-07-30 04:27:15 +00:00
|
|
|
}
|
2021-08-04 14:16:13 +00:00
|
|
|
else if (ttl_update_field == TTLUpdateField::MOVES_TTL)
|
2021-07-30 04:27:15 +00:00
|
|
|
{
|
2021-08-03 07:37:25 +00:00
|
|
|
data_part->ttl_infos.moves_ttl[ttl_update_key] = new_ttl_info;
|
2021-07-30 04:27:15 +00:00
|
|
|
}
|
2021-08-04 14:16:13 +00:00
|
|
|
else if (ttl_update_field == TTLUpdateField::GROUP_BY_TTL)
|
2021-07-30 04:27:15 +00:00
|
|
|
{
|
2021-08-03 07:37:25 +00:00
|
|
|
data_part->ttl_infos.group_by_ttl[ttl_update_key] = new_ttl_info;
|
2021-07-30 04:27:15 +00:00
|
|
|
data_part->ttl_infos.updatePartMinMaxTTL(new_ttl_info.min, new_ttl_info.max);
|
|
|
|
}
|
2021-08-04 14:16:13 +00:00
|
|
|
else if (ttl_update_field == TTLUpdateField::ROWS_WHERE_TTL)
|
2021-07-30 04:27:15 +00:00
|
|
|
{
|
2021-08-03 07:37:25 +00:00
|
|
|
data_part->ttl_infos.rows_where_ttl[ttl_update_key] = new_ttl_info;
|
|
|
|
data_part->ttl_infos.updatePartMinMaxTTL(new_ttl_info.min, new_ttl_info.max);
|
|
|
|
}
|
2021-08-04 14:16:13 +00:00
|
|
|
else if (ttl_update_field == TTLUpdateField::TABLE_TTL)
|
2021-08-03 07:37:25 +00:00
|
|
|
{
|
|
|
|
data_part->ttl_infos.table_ttl = new_ttl_info;
|
|
|
|
data_part->ttl_infos.updatePartMinMaxTTL(new_ttl_info.min, new_ttl_info.max);
|
|
|
|
}
|
2021-08-04 14:16:13 +00:00
|
|
|
else if (ttl_update_field == TTLUpdateField::COLUMNS_TTL)
|
2021-08-03 07:37:25 +00:00
|
|
|
{
|
|
|
|
data_part->ttl_infos.columns_ttl[ttl_update_key] = new_ttl_info;
|
2021-07-30 04:27:15 +00:00
|
|
|
data_part->ttl_infos.updatePartMinMaxTTL(new_ttl_info.min, new_ttl_info.max);
|
|
|
|
}
|
2021-07-31 12:36:40 +00:00
|
|
|
|
2020-12-25 14:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|