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

Method fillTableIfNeeded

src/Interpreters/InterpreterCreateQuery.cpp:2420–2484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2418}
2419
2420BlockIO InterpreterCreateQuery::fillTableIfNeeded(const ASTCreateQuery & create)
2421{
2422 /// If the query is a CREATE SELECT, insert the data into the table.
2423 if (create.isCreateQueryWithImmediateInsertSelect())
2424 {
2425 auto insert = make_intrusive<ASTInsertQuery>();
2426 insert->table_id = {create.getDatabase(), create.getTable(), create.uuid};
2427 if (create.is_window_view)
2428 {
2429 auto table = DatabaseCatalog::instance().getTable(insert->table_id, getContext());
2430 insert->select = typeid_cast<StorageWindowView *>(table.get())->getSourceTableSelectQuery();
2431 }
2432 else
2433 insert->select = create.select->clone();
2434
2435 return InterpreterInsertQuery(
2436 insert,
2437 getContext(),
2438 getContext()->getSettingsRef()[Setting::insert_allow_materialized_columns],
2439 /* no_squash */ false,
2440 /* no_destination */ false,
2441 /* async_isnert */ false)
2442 .execute();
2443 }
2444
2445 /// If the query is a CREATE TABLE .. CLONE AS ..., attach all partitions of the source table to the newly created table.
2446 if (create.is_clone_as && !as_table_saved.empty() && !create.is_create_empty && !create.is_ordinary_view
2447 && (!(create.is_materialized_view || create.is_window_view) || create.is_populate))
2448 {
2449 String as_database_name = getContext()->resolveDatabase(as_database_saved);
2450
2451 auto partition = make_intrusive<ASTPartition>();
2452 partition->all = true;
2453
2454 auto command = make_intrusive<ASTAlterCommand>();
2455 command->replace = false;
2456 command->type = ASTAlterCommand::REPLACE_PARTITION;
2457 command->partition = command->children.emplace_back(std::move(partition)).get();
2458 command->from_database = as_database_name;
2459 command->from_table = as_table_saved;
2460 command->to_database = create.getDatabase();
2461 command->to_table = create.getTable();
2462
2463 auto command_list = make_intrusive<ASTExpressionList>();
2464 command_list->children.push_back(command);
2465
2466 auto query = make_intrusive<ASTAlterQuery>();
2467 query->setDatabase(create.getDatabase());
2468 query->setTable(create.getTable());
2469 query->uuid = create.uuid;
2470 auto * alter = query->as<ASTAlterQuery>();
2471
2472 alter->alter_object = ASTAlterQuery::AlterObjectType::TABLE;
2473 alter->set(alter->command_list, command_list);
2474
2475 /// The result of this internal ALTER is not visible to the user,
2476 /// so disable verbose output to avoid creating a pulling pipeline
2477 /// that executeTrivialBlockIO cannot handle.

Callers

nothing calls this directly

Calls 15

resolveDatabaseMethod · 0.80
FieldClass · 0.70
getContextFunction · 0.50
getDatabaseMethod · 0.45
getTableMethod · 0.45
getMethod · 0.45
cloneMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected