aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Analyzer/TableExpressionModifiers.cpp
blob: c8002f44c9774d2a8520b2a10cb8a2c16cd3fe76 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <Analyzer/TableExpressionModifiers.h>

#include <Common/SipHash.h>

#include <IO/WriteBuffer.h>
#include <IO/WriteHelpers.h>
#include <IO/Operators.h>
#include <IO/WriteBufferFromString.h>

namespace DB
{

void TableExpressionModifiers::dump(WriteBuffer & buffer) const
{
    buffer << "final: " << has_final;

    if (sample_size_ratio)
        buffer << ", sample_size: " << ASTSampleRatio::toString(*sample_size_ratio);

    if (sample_offset_ratio)
        buffer << ", sample_offset: " << ASTSampleRatio::toString(*sample_offset_ratio);
}

void TableExpressionModifiers::updateTreeHash(SipHash & hash_state) const
{
    hash_state.update(has_final);
    hash_state.update(sample_size_ratio.has_value());
    hash_state.update(sample_offset_ratio.has_value());

    if (sample_size_ratio.has_value())
    {
        hash_state.update(sample_size_ratio->numerator);
        hash_state.update(sample_size_ratio->denominator);
    }

    if (sample_offset_ratio.has_value())
    {
        hash_state.update(sample_offset_ratio->numerator);
        hash_state.update(sample_offset_ratio->denominator);
    }
}

String TableExpressionModifiers::formatForErrorMessage() const
{
    WriteBufferFromOwnString buffer;
    if (has_final)
        buffer << "FINAL";

    if (sample_size_ratio)
    {
        if (has_final)
            buffer << ' ';
        buffer << "SAMPLE " << ASTSampleRatio::toString(*sample_size_ratio);
    }

    if (sample_offset_ratio)
    {
        if (has_final || sample_size_ratio)
            buffer << ' ';
        buffer << "OFFSET " << ASTSampleRatio::toString(*sample_offset_ratio);
    }

    return buffer.str();
}

}