aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ASTSetQuery.cpp
blob: 1b7b76fe2310b4cf52a972983c92f71b884626b9 (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
67
68
69
70
71
72
73
74
75
76
77
#include <Parsers/ASTSetQuery.h>
#include <Parsers/formatSettingName.h>
#include <Common/SipHash.h>
#include <Common/FieldVisitorHash.h>
#include <Common/FieldVisitorToString.h>
#include <IO/Operators.h>


namespace DB
{

void ASTSetQuery::updateTreeHashImpl(SipHash & hash_state) const
{
    for (const auto & change : changes)
    {
        hash_state.update(change.name.size());
        hash_state.update(change.name);
        applyVisitor(FieldVisitorHash(hash_state), change.value);
    }
}

void ASTSetQuery::formatImpl(const FormatSettings & format, FormatState &, FormatStateStacked) const
{
    if (is_standalone)
        format.ostr << (format.hilite ? hilite_keyword : "") << "SET " << (format.hilite ? hilite_none : "");

    bool first = true;

    for (const auto & change : changes)
    {
        if (!first)
            format.ostr << ", ";
        else
            first = false;

        formatSettingName(change.name, format.ostr);
        CustomType custom;
        if (!format.show_secrets && change.value.tryGet<CustomType>(custom) && custom.isSecret())
            format.ostr << " = " << custom.toString(false);
        else
            format.ostr << " = " << applyVisitor(FieldVisitorToString(), change.value);
    }

    for (const auto & setting_name : default_settings)
    {
        if (!first)
            format.ostr << ", ";
        else
            first = false;

        formatSettingName(setting_name, format.ostr);
        format.ostr << " = DEFAULT";
    }

    for (const auto & [name, value] : query_parameters)
    {
        if (!first)
            format.ostr << ", ";
        else
            first = false;

        formatSettingName(QUERY_PARAMETER_NAME_PREFIX + name, format.ostr);
        format.ostr << " = " << value;
    }
}

void ASTSetQuery::appendColumnName(WriteBuffer & ostr) const
{
    Hash hash = getTreeHash();

    writeCString("__settings_", ostr);
    writeText(hash.low64, ostr);
    ostr.write('_');
    writeText(hash.high64, ostr);
}

}