1 | #pragma once |
---|---|
2 | |
3 | #include <Parsers/IAST.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | |
10 | /// AST, EXPLAIN or other query with meaning of explanation query instead of execution |
11 | class ASTExplainQuery : public IAST |
12 | { |
13 | public: |
14 | enum ExplainKind |
15 | { |
16 | ParsedAST, |
17 | AnalyzedSyntax, |
18 | }; |
19 | |
20 | ASTExplainQuery(ExplainKind kind_) |
21 | : kind(kind_) |
22 | {} |
23 | |
24 | String getID(char delim) const override { return "Explain"+ (delim + toString(kind)); } |
25 | ExplainKind getKind() const { return kind; } |
26 | ASTPtr clone() const override { return std::make_shared<ASTExplainQuery>(*this); } |
27 | |
28 | protected: |
29 | void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override |
30 | { |
31 | settings.ostr << (settings.hilite ? hilite_keyword : "") << toString(kind) << (settings.hilite ? hilite_none : "") << " "; |
32 | children.at(0)->formatImpl(settings, state, frame); |
33 | } |
34 | |
35 | private: |
36 | ExplainKind kind; |
37 | |
38 | static String toString(ExplainKind kind) |
39 | { |
40 | switch (kind) |
41 | { |
42 | case ParsedAST: return "AST"; |
43 | case AnalyzedSyntax: return "ANALYZE"; |
44 | } |
45 | |
46 | __builtin_unreachable(); |
47 | } |
48 | }; |
49 | |
50 | } |
51 |