aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ASTAlterNamedCollectionQuery.cpp
blob: 6363a7306bda117aa1a7d47099a46a48ede48d5e (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
#include <Common/quoteString.h>
#include <Common/FieldVisitorToString.h>
#include <IO/Operators.h>
#include <Parsers/ASTAlterNamedCollectionQuery.h>
#include <Parsers/formatSettingName.h>

namespace DB
{

ASTPtr ASTAlterNamedCollectionQuery::clone() const
{
    return std::make_shared<ASTAlterNamedCollectionQuery>(*this);
}

void ASTAlterNamedCollectionQuery::formatImpl(const IAST::FormatSettings & settings, IAST::FormatState &, IAST::FormatStateStacked) const
{
    settings.ostr << (settings.hilite ? hilite_keyword : "") << "Alter NAMED COLLECTION ";
    if (if_exists)
        settings.ostr << "IF EXISTS ";
    settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(collection_name) << (settings.hilite ? hilite_none : "");
    formatOnCluster(settings);
    if (!changes.empty())
    {
        settings.ostr << (settings.hilite ? hilite_keyword : "") << " SET " << (settings.hilite ? hilite_none : "");
        bool first = true;
        for (const auto & change : changes)
        {
            if (!first)
                settings.ostr << ", ";
            else
                first = false;

            formatSettingName(change.name, settings.ostr);
            if (settings.show_secrets)
                settings.ostr << " = " << applyVisitor(FieldVisitorToString(), change.value);
            else
                settings.ostr << " = '[HIDDEN]'";
        }
    }
    if (!delete_keys.empty())
    {
        settings.ostr << (settings.hilite ? hilite_keyword : "") << " DELETE " << (settings.hilite ? hilite_none : "");
        bool first = true;
        for (const auto & key : delete_keys)
        {
            if (!first)
                settings.ostr << ", ";
            else
                first = false;

            formatSettingName(key, settings.ostr);
        }
    }
}

}