Repository: ClickHouse/ClickHouse
File: src/Databases/DataLake/DatabaseDataLake.cpp (C++)

Code before:
}

ASTPtr DatabaseDataLake::getCreateDatabaseQueryImpl() const
{
    const auto & create_query = make_intrusive<ASTCreateQuery>();
    create_query->setDatabase(database_name);
    create_query->set(create_query->storage, database_engine_definition);
    create_query->uuid = db_uuid;
    return create_query;
}

ASTPtr DatabaseDataLake::getCreateTableQueryImpl(
    const String & name,
    ContextPtr /* context_ */,
    bool throw_on_error) const
{
    auto catalog = getCatalog();
    auto table_metadata = DataLake::TableMetadata().withLocation().withSchema();

    const auto [namespace_name, table_name] = DataLake::parseTableName(name);

    if (!catalog->tryGetTableMetadata(namespace_name, table_name, table_metadata))
    {
        if (throw_on_error)
            throw Exception(ErrorCodes::CANNOT_GET_CREATE_TABLE_QUERY, "Table `{}` doesn't exist", name);
        return {};
    }

    auto create_table_query = make_intrusive<ASTCreateQuery>();
    auto table_storage_define = table_engine_definition->clone();

    auto * storage = table_storage_define->as<ASTStorage>();
    storage->engine->kind = ASTFunction::Kind::TABLE_ENGINE;
    if (!table_metadata.isDefaultReadableTable())
        storage->engine->name = DataLake::FAKE_TABLE_ENGINE_NAME_FOR_UNREADABLE_TABLES;

    storage->settings = {};

    create_table_query->set(create_table_query->storage, table_storage_define);

    auto columns_declare_list = make_intrusive<ASTColumns>();
    auto columns_expression_list = make_intrusive<ASTExpressionList>();

    columns_declare_list->set(columns_declare_list->columns, columns_expression_list);
    create_table_query->set(create_table_query->columns_list, columns_declare_list);

    create_table_query->setTable(name);
    create_table_query->setDatabase(getDatabaseName());

    for (const auto & column_type_and_name : table_metadata.getSchema())
    {

Review comment (refactor):
Should we move this logic into `getTablesIterator` now?

Code after:

std::vector<LightWeightTableDetails> DatabaseDataLake::getLightweightTablesIterator(
    ContextPtr /*context_*/,
    const FilterByNameFunction & filter_by_table_name,
    bool /*skip_not_loaded*/) const
{
    auto catalog = getCatalog();
    DB::Names iceberg_tables;
    std::vector<LightWeightTableDetails> result;

    /// Do not throw here, because this might be, for example, a query to system.tables.
    /// It must not fail on case of some datalake error.
    try
    {
        iceberg_tables = catalog->getTables();
    }
    catch (...)
    {
        tryLogCurrentException(__PRETTY_FUNCTION__);
    }

    for (const auto & table_name : iceberg_tables)
    {
        if (filter_by_table_name && !filter_by_table_name(table_name))
            continue;
        result.emplace_back(table_name);
    }

    return result;
}

ASTPtr DatabaseDataLake::getCreateDatabaseQueryImpl() const
{
    const auto & create_query = make_intrusive<ASTCreateQuery>();
    create_query->setDatabase(database_name);
    create_query->set(create_query->storage, database_engine_definition);
    create_query->uuid = db_uuid;
    return create_query;
}

ASTPtr DatabaseDataLake::getCreateTableQueryImpl(
    const String & name,
    ContextPtr /* context_ */,
    bool throw_on_error) const
{
    auto catalog = getCatalog();
    auto table_metadata = DataLake::TableMetadata().withLocation().withSchema();

    const auto [namespace_name, table_name] = DataLake::parseTableName(name);

    if (!catalog->tryGetTableMetadata(namespace_name, table_name, table_metadata))