1 | #include <Parsers/IAST.h> |
---|---|
2 | #include <Parsers/ASTSystemQuery.h> |
3 | #include <Common/quoteString.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | |
10 | namespace ErrorCodes |
11 | { |
12 | extern const int BAD_TYPE_OF_FIELD; |
13 | extern const int NOT_IMPLEMENTED; |
14 | } |
15 | |
16 | |
17 | const char * ASTSystemQuery::typeToString(Type type) |
18 | { |
19 | switch (type) |
20 | { |
21 | case Type::SHUTDOWN: |
22 | return "SHUTDOWN"; |
23 | case Type::KILL: |
24 | return "KILL"; |
25 | case Type::DROP_DNS_CACHE: |
26 | return "DROP DNS CACHE"; |
27 | case Type::DROP_MARK_CACHE: |
28 | return "DROP MARK CACHE"; |
29 | case Type::DROP_UNCOMPRESSED_CACHE: |
30 | return "DROP UNCOMPRESSED CACHE"; |
31 | #if USE_EMBEDDED_COMPILER |
32 | case Type::DROP_COMPILED_EXPRESSION_CACHE: |
33 | return "DROP COMPILED EXPRESSION CACHE"; |
34 | #endif |
35 | case Type::STOP_LISTEN_QUERIES: |
36 | return "STOP LISTEN QUERIES"; |
37 | case Type::START_LISTEN_QUERIES: |
38 | return "START LISTEN QUERIES"; |
39 | case Type::RESTART_REPLICAS: |
40 | return "RESTART REPLICAS"; |
41 | case Type::RESTART_REPLICA: |
42 | return "RESTART REPLICA"; |
43 | case Type::SYNC_REPLICA: |
44 | return "SYNC REPLICA"; |
45 | case Type::FLUSH_DISTRIBUTED: |
46 | return "FLUSH DISTRIBUTED"; |
47 | case Type::RELOAD_DICTIONARY: |
48 | return "RELOAD DICTIONARY"; |
49 | case Type::RELOAD_DICTIONARIES: |
50 | return "RELOAD DICTIONARIES"; |
51 | case Type::RELOAD_EMBEDDED_DICTIONARIES: |
52 | return "RELOAD EMBEDDED DICTIONARIES"; |
53 | case Type::RELOAD_CONFIG: |
54 | return "RELOAD CONFIG"; |
55 | case Type::STOP_MERGES: |
56 | return "STOP MERGES"; |
57 | case Type::START_MERGES: |
58 | return "START MERGES"; |
59 | case Type::STOP_TTL_MERGES: |
60 | return "STOP TTL MERGES"; |
61 | case Type::START_TTL_MERGES: |
62 | return "START TTL MERGES"; |
63 | case Type::STOP_MOVES: |
64 | return "STOP MOVES"; |
65 | case Type::START_MOVES: |
66 | return "START MOVES"; |
67 | case Type::STOP_FETCHES: |
68 | return "STOP FETCHES"; |
69 | case Type::START_FETCHES: |
70 | return "START FETCHES"; |
71 | case Type::STOP_REPLICATED_SENDS: |
72 | return "STOP REPLICATED SENDS"; |
73 | case Type::START_REPLICATED_SENDS: |
74 | return "START REPLICATED SENDS"; |
75 | case Type::STOP_REPLICATION_QUEUES: |
76 | return "STOP REPLICATION QUEUES"; |
77 | case Type::START_REPLICATION_QUEUES: |
78 | return "START REPLICATION QUEUES"; |
79 | case Type::STOP_DISTRIBUTED_SENDS: |
80 | return "STOP DISTRIBUTED SENDS"; |
81 | case Type::START_DISTRIBUTED_SENDS: |
82 | return "START DISTRIBUTED SENDS"; |
83 | case Type::FLUSH_LOGS: |
84 | return "FLUSH LOGS"; |
85 | default: |
86 | throw Exception("Unknown SYSTEM query command", ErrorCodes::BAD_TYPE_OF_FIELD); |
87 | } |
88 | } |
89 | |
90 | |
91 | void ASTSystemQuery::formatImpl(const FormatSettings & settings, FormatState &, FormatStateStacked) const |
92 | { |
93 | settings.ostr << (settings.hilite ? hilite_keyword : "") << "SYSTEM "<< (settings.hilite ? hilite_none : ""); |
94 | settings.ostr << typeToString(type); |
95 | |
96 | auto print_database_table = [&] |
97 | { |
98 | settings.ostr << " "; |
99 | if (!database.empty()) |
100 | { |
101 | settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(database) |
102 | << (settings.hilite ? hilite_none : "") << "."; |
103 | } |
104 | settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(table) |
105 | << (settings.hilite ? hilite_none : ""); |
106 | }; |
107 | |
108 | auto print_database_dictionary = [&] |
109 | { |
110 | settings.ostr << " "; |
111 | if (!database.empty()) |
112 | { |
113 | settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(database) |
114 | << (settings.hilite ? hilite_none : "") << "."; |
115 | } |
116 | settings.ostr << (settings.hilite ? hilite_identifier : "") << backQuoteIfNeed(target_dictionary) |
117 | << (settings.hilite ? hilite_none : ""); |
118 | }; |
119 | |
120 | if (!cluster.empty()) |
121 | formatOnCluster(settings); |
122 | |
123 | if ( type == Type::STOP_MERGES |
124 | || type == Type::START_MERGES |
125 | || type == Type::STOP_TTL_MERGES |
126 | || type == Type::START_TTL_MERGES |
127 | || type == Type::STOP_MOVES |
128 | || type == Type::START_MOVES |
129 | || type == Type::STOP_FETCHES |
130 | || type == Type::START_FETCHES |
131 | || type == Type::STOP_REPLICATED_SENDS |
132 | || type == Type::START_REPLICATED_SENDS |
133 | || type == Type::STOP_REPLICATION_QUEUES |
134 | || type == Type::START_REPLICATION_QUEUES |
135 | || type == Type::STOP_DISTRIBUTED_SENDS |
136 | || type == Type::START_DISTRIBUTED_SENDS) |
137 | { |
138 | if (!table.empty()) |
139 | print_database_table(); |
140 | } |
141 | else if (type == Type::RESTART_REPLICA || type == Type::SYNC_REPLICA || type == Type::FLUSH_DISTRIBUTED) |
142 | { |
143 | print_database_table(); |
144 | } |
145 | else if (type == Type::RELOAD_DICTIONARY) |
146 | print_database_dictionary(); |
147 | } |
148 | |
149 | |
150 | } |
151 |