MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / parseDropReplica

Function parseDropReplica

src/Parsers/ParserSystemQuery.cpp:176–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

174}
175
176[[nodiscard]] static bool parseDropReplica(boost::intrusive_ptr<ASTSystemQuery> & res, IParser::Pos & pos, Expected & expected, bool database)
177{
178 if (!parseQueryWithOnCluster(res, pos, expected))
179 return false;
180
181 ASTPtr ast;
182 if (!ParserStringLiteral{}.parse(pos, ast, expected))
183 return false;
184 res->replica = ast->as<ASTLiteral &>().value.safeGet<String>();
185
186 if (ParserKeyword{Keyword::FROM_SHARD}.ignore(pos, expected))
187 {
188 if (!ParserStringLiteral{}.parse(pos, ast, expected))
189 return false;
190 res->shard = ast->as<ASTLiteral &>().value.safeGet<String>();
191 }
192
193 if (ParserKeyword{Keyword::FROM}.ignore(pos, expected))
194 {
195 // way 1. parse replica database
196 // way 2. parse replica table
197 // way 3. parse replica zkpath
198 if (ParserKeyword{Keyword::DATABASE}.ignore(pos, expected))
199 {
200 ParserIdentifier database_parser;
201 if (!database_parser.parse(pos, res->database, expected))
202 return false;
203 }
204 else if (!database && ParserKeyword{Keyword::TABLE}.ignore(pos, expected))
205 {
206 parseDatabaseAndTableAsAST(pos, expected, res->database, res->table);
207 }
208 else if (ParserKeyword{Keyword::ZKPATH}.ignore(pos, expected))
209 {
210 ASTPtr path_ast;
211 if (!ParserStringLiteral{}.parse(pos, path_ast, expected))
212 return false;
213 String zk_path = path_ast->as<ASTLiteral &>().value.safeGet<String>();
214 if (!zk_path.empty() && zk_path[zk_path.size() - 1] == '/')
215 zk_path.pop_back();
216 if (!zk_path.empty())
217 {
218 res->full_replica_zk_path = std::move(zk_path);
219 res->zk_name = zkutil::extractZooKeeperName(res->full_replica_zk_path);
220 res->replica_zk_path = zkutil::extractZooKeeperPath(res->full_replica_zk_path, /*check_starts_with_slash*/false);
221 }
222 }
223 else
224 return false;
225
226 if (database && ParserKeyword{Keyword::WITH_TABLES}.ignore(pos, expected))
227 res->with_tables = true;
228 }
229 else
230 res->is_drop_whole_replica = true;
231
232 return true;
233}

Callers 1

parseImplMethod · 0.85

Calls 9

parseQueryWithOnClusterFunction · 0.85
extractZooKeeperNameFunction · 0.85
extractZooKeeperPathFunction · 0.85
parseMethod · 0.45
ignoreMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
pop_backMethod · 0.45

Tested by

no test coverage detected