ClickHouse

Форк
0
/
ITTLAlgorithm.cpp 
66 строк · 2.2 Кб
1
#include <Processors/TTL/ITTLAlgorithm.h>
2
#include <Columns/ColumnVector.h>
3
#include <Columns/ColumnConst.h>
4

5
namespace DB
6
{
7

8
namespace ErrorCodes
9
{
10
    extern const int LOGICAL_ERROR;
11
}
12

13
ITTLAlgorithm::ITTLAlgorithm(
14
    const TTLExpressions & ttl_expressions_, const TTLDescription & description_, const TTLInfo & old_ttl_info_, time_t current_time_, bool force_)
15
    : ttl_expressions(ttl_expressions_)
16
    , description(description_)
17
    , old_ttl_info(old_ttl_info_)
18
    , current_time(current_time_)
19
    , force(force_)
20
    , date_lut(DateLUT::instance())
21
{
22
}
23

24
bool ITTLAlgorithm::isTTLExpired(time_t ttl) const
25
{
26
    return (ttl && (ttl <= current_time));
27
}
28

29
ColumnPtr ITTLAlgorithm::executeExpressionAndGetColumn(
30
    const ExpressionActionsPtr & expression, const Block & block, const String & result_column)
31
{
32
    if (!expression)
33
        return nullptr;
34

35
    if (block.has(result_column))
36
        return block.getByName(result_column).column;
37

38
    Block block_copy;
39
    for (const auto & column_name : expression->getRequiredColumns())
40
        block_copy.insert(block.getByName(column_name));
41

42
    /// Keep number of rows for const expression.
43
    size_t num_rows = block.rows();
44
    expression->execute(block_copy, num_rows);
45

46
    return block_copy.getByName(result_column).column;
47
}
48

49
UInt32 ITTLAlgorithm::getTimestampByIndex(const IColumn * column, size_t index) const
50
{
51
    if (const ColumnUInt16 * column_date = typeid_cast<const ColumnUInt16 *>(column))
52
        return static_cast<UInt32>(date_lut.fromDayNum(DayNum(column_date->getData()[index])));
53
    else if (const ColumnUInt32 * column_date_time = typeid_cast<const ColumnUInt32 *>(column))
54
        return column_date_time->getData()[index];
55
    else if (const ColumnConst * column_const = typeid_cast<const ColumnConst *>(column))
56
    {
57
        if (typeid_cast<const ColumnUInt16 *>(&column_const->getDataColumn()))
58
            return static_cast<UInt32>(date_lut.fromDayNum(DayNum(column_const->getValue<UInt16>())));
59
        else if (typeid_cast<const ColumnUInt32 *>(&column_const->getDataColumn()))
60
            return column_const->getValue<UInt32>();
61
    }
62

63
    throw Exception(ErrorCodes::LOGICAL_ERROR, "Unexpected type of result TTL column");
64
}
65

66
}
67

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.