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

Function maybeRemoveOnCluster

src/Interpreters/executeDDLQueryOnCluster.cpp:225–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223}
224
225bool maybeRemoveOnCluster(const ASTPtr & query_ptr, ContextPtr context)
226{
227 const auto * query = dynamic_cast<const ASTQueryWithTableAndOutput *>(query_ptr.get());
228 if (!query || !query->table)
229 return false;
230
231 String database_name = query->getDatabase();
232 if (database_name.empty())
233 database_name = context->getCurrentDatabase();
234
235 auto * query_on_cluster = dynamic_cast<ASTQueryWithOnCluster *>(query_ptr.get());
236 auto database = DatabaseCatalog::instance().tryGetDatabase(database_name);
237 if (database && database->shouldReplicateQuery(context, query_ptr))
238 {
239 if (!context->getSettingsRef()[Setting::ignore_on_cluster_for_replicated_database] && database_name != query_on_cluster->cluster)
240 return false;
241 /// It's Replicated database and query is replicated on database level,
242 /// so ON CLUSTER clause is redundant.
243 query_on_cluster->cluster.clear();
244 return true;
245 }
246
247 return false;
248}
249
250}

Callers 6

executeMethod · 0.85
executeToTableMethod · 0.85
executeMethod · 0.85
executeToTableImplMethod · 0.85
executeMethod · 0.85

Calls 7

getCurrentDatabaseMethod · 0.80
tryGetDatabaseMethod · 0.80
getMethod · 0.45
getDatabaseMethod · 0.45
emptyMethod · 0.45
shouldReplicateQueryMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected