| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Core/Field.h> |
| 4 | #include <Core/Types.h> |
| 5 | #include <Common/FieldVisitors.h> |
| 6 | #include <Common/quoteString.h> |
| 7 | #include <Parsers/ASTExpressionList.h> |
| 8 | #include <Parsers/ASTFunction.h> |
| 9 | #include <Parsers/IAST.h> |
| 10 | |
| 11 | #include <vector> |
| 12 | |
| 13 | |
| 14 | namespace DB |
| 15 | { |
| 16 | |
| 17 | /** name BY expr TYPE typename(args) GRANULARITY int in create query |
| 18 | */ |
| 19 | class ASTIndexDeclaration : public IAST |
| 20 | { |
| 21 | public: |
| 22 | String name; |
| 23 | IAST * expr; |
| 24 | ASTFunction * type; |
| 25 | UInt64 granularity; |
| 26 | |
| 27 | /** Get the text that identifies this element. */ |
| 28 | String getID(char) const override { return "Index"; } |
| 29 | |
| 30 | ASTPtr clone() const override |
| 31 | { |
| 32 | auto res = std::make_shared<ASTIndexDeclaration>(); |
| 33 | |
| 34 | res->name = name; |
| 35 | res->granularity = granularity; |
| 36 | |
| 37 | if (expr) |
| 38 | res->set(res->expr, expr->clone()); |
| 39 | if (type) |
| 40 | res->set(res->type, type->clone()); |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override |
| 45 | { |
| 46 | frame.need_parens = false; |
| 47 | std::string indent_str = s.one_line ? "": std::string(4 * frame.indent, ' '); |
| 48 | |
| 49 | s.ostr << s.nl_or_ws << indent_str; |
| 50 | s.ostr << backQuoteIfNeed(name); |
| 51 | s.ostr << " "; |
| 52 | expr->formatImpl(s, state, frame); |
| 53 | s.ostr << (s.hilite ? hilite_keyword : "") << " TYPE "<< (s.hilite ? hilite_none : ""); |
| 54 | type->formatImpl(s, state, frame); |
| 55 | s.ostr << (s.hilite ? hilite_keyword : "") << " GRANULARITY "<< (s.hilite ? hilite_none : ""); |
| 56 | s.ostr << granularity; |
| 57 | } |
| 58 | }; |
| 59 | |
| 60 | } |
| 61 |