aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/ASTIndexDeclaration.cpp
blob: 12d59681cc395f2f3ed8a12888ec3d90371073d4 (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
#include <Parsers/ASTIndexDeclaration.h>

#include <Common/quoteString.h>
#include <IO/Operators.h>
#include <Parsers/ASTFunction.h>


namespace DB
{

ASTPtr ASTIndexDeclaration::clone() const
{
    auto res = std::make_shared<ASTIndexDeclaration>();

    res->name = name;
    if (granularity)
        res->granularity = granularity;
    if (expr)
        res->set(res->expr, expr->clone());
    if (type)
        res->set(res->type, type->clone());
    return res;
}


void ASTIndexDeclaration::formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const
{
    if (expr)
    {
        if (part_of_create_index_query)
        {
            if (expr->as<ASTExpressionList>())
            {
                s.ostr << "(";
                expr->formatImpl(s, state, frame);
                s.ostr << ")";
            }
            else
            expr->formatImpl(s, state, frame);
        }
        else
        {
            s.ostr << backQuoteIfNeed(name);
            s.ostr << " ";
            expr->formatImpl(s, state, frame);
        }
    }

    if (type)
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << " TYPE " << (s.hilite ? hilite_none : "");
        type->formatImpl(s, state, frame);
    }
    if (granularity)
    {
        s.ostr << (s.hilite ? hilite_keyword : "") << " GRANULARITY " << (s.hilite ? hilite_none : "");
        s.ostr << granularity;
    }
}

}