2019-04-15 09:30:45 +00:00
|
|
|
#pragma once
|
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <Storages/MergeTree/MergeTreeDataPart.h>
|
|
|
|
#include <Core/Block.h>
|
|
|
|
|
|
|
|
#include <common/DateLUT.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class TTLBlockInputStream : public IBlockInputStream
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TTLBlockInputStream(
|
|
|
|
const BlockInputStreamPtr & input_,
|
|
|
|
const MergeTreeData & storage_,
|
|
|
|
const MergeTreeData::MutableDataPartPtr & data_part_,
|
2019-08-01 11:10:42 +00:00
|
|
|
time_t current_time,
|
|
|
|
bool force_
|
2019-04-15 09:30:45 +00:00
|
|
|
);
|
|
|
|
|
2019-08-01 15:36:12 +00:00
|
|
|
String getName() const override { return "TTL"; }
|
2019-04-15 09:30:45 +00:00
|
|
|
|
2019-07-01 14:09:22 +00:00
|
|
|
Block getHeader() const override { return header; }
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Block readImpl() override;
|
|
|
|
|
|
|
|
/// Finalizes ttl infos and updates data part
|
|
|
|
void readSuffixImpl() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const MergeTreeData & storage;
|
|
|
|
|
|
|
|
/// ttl_infos and empty_columns are updating while reading
|
|
|
|
const MergeTreeData::MutableDataPartPtr & data_part;
|
|
|
|
|
|
|
|
time_t current_time;
|
2019-08-01 11:10:42 +00:00
|
|
|
bool force;
|
2019-04-15 09:30:45 +00:00
|
|
|
|
|
|
|
MergeTreeDataPart::TTLInfos old_ttl_infos;
|
|
|
|
MergeTreeDataPart::TTLInfos new_ttl_infos;
|
|
|
|
NameSet empty_columns;
|
|
|
|
|
|
|
|
size_t rows_removed = 0;
|
|
|
|
Logger * log;
|
|
|
|
DateLUTImpl date_lut;
|
|
|
|
|
|
|
|
std::unordered_map<String, String> defaults_result_column;
|
|
|
|
ExpressionActionsPtr defaults_expression;
|
2019-07-01 12:50:50 +00:00
|
|
|
|
|
|
|
Block header;
|
2019-04-15 09:30:45 +00:00
|
|
|
private:
|
2019-08-01 11:10:42 +00:00
|
|
|
/// Removes values with expired ttl and computes new_ttl_infos and empty_columns for part
|
2019-04-15 09:30:45 +00:00
|
|
|
void removeValuesWithExpiredColumnTTL(Block & block);
|
|
|
|
|
2019-08-01 11:10:42 +00:00
|
|
|
/// Removes rows with expired table ttl and computes new ttl_infos for part
|
2019-04-15 09:30:45 +00:00
|
|
|
void removeRowsWithExpiredTableTTL(Block & block);
|
|
|
|
|
|
|
|
UInt32 getTimestampByIndex(const IColumn * column, size_t ind);
|
2019-08-01 11:10:42 +00:00
|
|
|
bool isTTLExpired(time_t ttl);
|
2019-04-15 09:30:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|