| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Parsers/ASTQueryWithTableAndOutput.h> |
| 4 | #include <Common/quoteString.h> |
| 5 | |
| 6 | |
| 7 | namespace DB |
| 8 | { |
| 9 | |
| 10 | struct ASTExistsTableQueryIDAndQueryNames |
| 11 | { |
| 12 | static constexpr auto ID = "ExistsTableQuery"; |
| 13 | static constexpr auto Query = "EXISTS TABLE"; |
| 14 | static constexpr auto QueryTemporary = "EXISTS TEMPORARY TABLE"; |
| 15 | }; |
| 16 | |
| 17 | struct ASTExistsDictionaryQueryIDAndQueryNames |
| 18 | { |
| 19 | static constexpr auto ID = "ExistsDictionaryQuery"; |
| 20 | static constexpr auto Query = "EXISTS DICTIONARY"; |
| 21 | /// No temporary dictionaries are supported, just for parsing |
| 22 | static constexpr auto QueryTemporary = "EXISTS TEMPORARY DICTIONARY"; |
| 23 | }; |
| 24 | |
| 25 | struct ASTShowCreateTableQueryIDAndQueryNames |
| 26 | { |
| 27 | static constexpr auto ID = "ShowCreateTableQuery"; |
| 28 | static constexpr auto Query = "SHOW CREATE TABLE"; |
| 29 | static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY TABLE"; |
| 30 | }; |
| 31 | |
| 32 | struct ASTShowCreateDatabaseQueryIDAndQueryNames |
| 33 | { |
| 34 | static constexpr auto ID = "ShowCreateDatabaseQuery"; |
| 35 | static constexpr auto Query = "SHOW CREATE DATABASE"; |
| 36 | static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY DATABASE"; |
| 37 | }; |
| 38 | |
| 39 | struct ASTShowCreateDictionaryQueryIDAndQueryNames |
| 40 | { |
| 41 | static constexpr auto ID = "ShowCreateDictionaryQuery"; |
| 42 | static constexpr auto Query = "SHOW CREATE DICTIONARY"; |
| 43 | /// No temporary dictionaries are supported, just for parsing |
| 44 | static constexpr auto QueryTemporary = "SHOW CREATE TEMPORARY DICTIONARY"; |
| 45 | }; |
| 46 | |
| 47 | struct ASTDescribeQueryExistsQueryIDAndQueryNames |
| 48 | { |
| 49 | static constexpr auto ID = "DescribeQuery"; |
| 50 | static constexpr auto Query = "DESCRIBE TABLE"; |
| 51 | static constexpr auto QueryTemporary = "DESCRIBE TEMPORARY TABLE"; |
| 52 | }; |
| 53 | |
| 54 | using ASTExistsTableQuery = ASTQueryWithTableAndOutputImpl<ASTExistsTableQueryIDAndQueryNames>; |
| 55 | using ASTExistsDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTExistsDictionaryQueryIDAndQueryNames>; |
| 56 | using ASTShowCreateTableQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateTableQueryIDAndQueryNames>; |
| 57 | using ASTShowCreateDictionaryQuery = ASTQueryWithTableAndOutputImpl<ASTShowCreateDictionaryQueryIDAndQueryNames>; |
| 58 | |
| 59 | class ASTShowCreateDatabaseQuery : public ASTQueryWithTableAndOutputImpl<ASTShowCreateDatabaseQueryIDAndQueryNames> |
| 60 | { |
| 61 | protected: |
| 62 | void formatQueryImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const override |
| 63 | { |
| 64 | settings.ostr << (settings.hilite ? hilite_keyword : "") << ASTShowCreateDatabaseQueryIDAndQueryNames::Query |
| 65 | << " "<< (settings.hilite ? hilite_none : "") << backQuoteIfNeed(database); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | class ASTDescribeQuery : public ASTQueryWithOutput |
| 70 | { |
| 71 | public: |
| 72 | ASTPtr table_expression; |
| 73 | |
| 74 | String getID(char) const override { return "DescribeQuery"; } |
| 75 | |
| 76 | ASTPtr clone() const override |
| 77 | { |
| 78 | auto res = std::make_shared<ASTDescribeQuery>(*this); |
| 79 | res->children.clear(); |
| 80 | if (table_expression) |
| 81 | { |
| 82 | res->table_expression = table_expression->clone(); |
| 83 | res->children.push_back(res->table_expression); |
| 84 | } |
| 85 | cloneOutputOptions(*res); |
| 86 | return res; |
| 87 | } |
| 88 | |
| 89 | protected: |
| 90 | void formatQueryImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override |
| 91 | { |
| 92 | settings.ostr << (settings.hilite ? hilite_keyword : "") |
| 93 | << "DESCRIBE TABLE "<< (settings.hilite ? hilite_none : ""); |
| 94 | table_expression->formatImpl(settings, state, frame); |
| 95 | } |
| 96 | |
| 97 | }; |
| 98 | |
| 99 | } |
| 100 |