Repository: ClickHouse/ClickHouse
File: src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp (C++)

Code before:
        {
            arg = args[0]->as<ASTLiteral>()->value.safeGet<UInt64>();
            column_name = args[1]->as<ASTIdentifier>()->name();
        }
        else
            column_name = args[0]->as<ASTIdentifier>()->name();

        if (!clickhouse_name_to_iceberg.contains(clickhouse_name))
            throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unsupported function {} for iceberg", clickhouse_name);
        const auto & transform_base = clickhouse_name_to_iceberg.at(clickhouse_name);

        String transform = transform_base;
        if (arg.has_value())
            transform += "[" + std::to_string(arg.value()) + "]";

        return {transform, column_name};
    };

    if (auto * func = object->as<ASTFunction>(); func->name != "tuple")
    {
        return parse_function(object);
    }

    auto function_desc = object->children[0]->children[i];
    if (auto * identifier = function_desc->as<ASTIdentifier>(); identifier)
        return {"identity", identifier->name()};

    function_desc = function_desc->children[0];
    if (auto * identifier = function_desc->as<ASTIdentifier>(); identifier)
        return {"identity", identifier->name()};

    return parse_function(function_desc);
}

std::pair<Poco::JSON::Object::Ptr, String> createEmptyMetadataFile(
    String path_location,
    const ColumnsDescription & columns,
    ASTPtr partition_by,
    ASTPtr order_by,
    ContextPtr context,
    UInt64 format_version)
{
    std::unordered_map<String, Int32> column_name_to_source_id;
    static Poco::UUIDGenerator uuid_generator;

    Poco::JSON::Object::Ptr new_metadata_file_content = new Poco::JSON::Object;
    new_metadata_file_content->set(Iceberg::f_format_version, format_version);
    new_metadata_file_content->set(Iceberg::f_table_uuid, uuid_generator.createRandom().toString());
    new_metadata_file_content->set(Iceberg::f_location, path_location);
    if (format_version > 1)
        new_metadata_file_content->set(Iceberg::f_last_sequence_number, 0);

Review comment (suggestion):
`object->children[0]` here should be `ASTExpressionList`, right? As I remember this is usually checked with `as` before getting its children for ASTFunction

Code after:
        {
            arg = args[0]->as<ASTLiteral>()->value.safeGet<UInt64>();
            column_name = args[1]->as<ASTIdentifier>()->name();
        }
        else
            column_name = args[0]->as<ASTIdentifier>()->name();

        if (!clickhouse_name_to_iceberg.contains(clickhouse_name))
            throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unsupported function {} for iceberg", clickhouse_name);
        const auto & transform_base = clickhouse_name_to_iceberg.at(clickhouse_name);

        String transform = transform_base;
        if (arg.has_value())
            transform += "[" + std::to_string(arg.value()) + "]";

        return {transform, column_name};
    };

    if (auto * func = object->as<ASTFunction>(); func->name != "tuple")
    {
        return parse_function(object);
    }

    chassert(!object->children.empty());
    chassert(object->children[0]->as<ASTExpressionList>());
    auto function_desc = object->children[0]->children[i];
    if (auto * identifier = function_desc->as<ASTIdentifier>(); identifier)
        return {"identity", identifier->name()};

    chassert(!function_desc->children.empty());
    function_desc = function_desc->children[0];
    if (auto * identifier = function_desc->as<ASTIdentifier>(); identifier)
        return {"identity", identifier->name()};

    return parse_function(function_desc);
}

std::pair<Poco::JSON::Object::Ptr, String> createEmptyMetadataFile(
    String path_location,
    const ColumnsDescription & columns,
    ASTPtr partition_by,
    ASTPtr order_by,
    ContextPtr context,
    UInt64 format_version)
{
    std::unordered_map<String, Int32> column_name_to_source_id;
    static Poco::UUIDGenerator uuid_generator;

    Poco::JSON::Object::Ptr new_metadata_file_content = new Poco::JSON::Object;
    new_metadata_file_content->set(Iceberg::f_format_version, format_version);
    new_metadata_file_content->set(Iceberg::f_table_uuid, uuid_generator.createRandom().toString());