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

Method distributedWrite

src/Storages/StorageDistributed.cpp:1368–1410  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1366
1367
1368std::optional<QueryPipeline> StorageDistributed::distributedWrite(const ASTInsertQuery & query, ContextPtr local_context)
1369{
1370 const Settings & settings = local_context->getSettingsRef();
1371 if (settings[Setting::max_distributed_depth] && local_context->getClientInfo().distributed_depth >= settings[Setting::max_distributed_depth])
1372 throw Exception(ErrorCodes::TOO_LARGE_DISTRIBUTED_DEPTH, "Maximum distributed depth exceeded");
1373
1374 auto & select = query.select->as<ASTSelectWithUnionQuery &>();
1375
1376 StoragePtr src_storage;
1377
1378 /// Distributed write only works in the most trivial case INSERT ... SELECT
1379 /// without any unions or joins on the right side
1380 if (select.list_of_selects->children.size() == 1)
1381 {
1382 if (auto * select_query = select.list_of_selects->children.at(0)->as<ASTSelectQuery>())
1383 {
1384 if (local_context->getSettingsRef()[Setting::enable_global_with_statement])
1385 ApplyWithAliasVisitor::visit(select.list_of_selects->children.at(0));
1386 ApplyWithSubqueryVisitor(local_context).visit(select.list_of_selects->children.at(0));
1387
1388 JoinedTables joined_tables(Context::createCopy(local_context), *select_query);
1389
1390 if (joined_tables.tablesCount() == 1)
1391 {
1392 src_storage = joined_tables.getLeftTableStorage();
1393 }
1394 }
1395 }
1396
1397 if (!src_storage)
1398 return {};
1399
1400 if (auto src_distributed = std::dynamic_pointer_cast<StorageDistributed>(src_storage))
1401 {
1402 return distributedWriteBetweenDistributedTables(*src_distributed, query, local_context);
1403 }
1404 if (auto src_storage_cluster = std::dynamic_pointer_cast<IStorageCluster>(src_storage))
1405 {
1406 return distributedWriteFromClusterStorage(*src_storage_cluster, query, local_context);
1407 }
1408
1409 return {};
1410}
1411
1412
1413void StorageDistributed::checkAlterIsPossible(const AlterCommands & commands, ContextPtr local_context) const

Callers

nothing calls this directly

Calls 7

tablesCountMethod · 0.80
getLeftTableStorageMethod · 0.80
ExceptionClass · 0.50
sizeMethod · 0.45
atMethod · 0.45
visitMethod · 0.45

Tested by

no test coverage detected