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

Code before:
        {
            auto partition_field = getPartitionField(partition_by, column_name_to_source_id, partition_iter);
            fields->add(partition_field);
        }
    }
    else
        partition_iter = 0;

    result->set(Iceberg::f_fields, fields);
    return {result, partition_iter};
}

std::pair<String, String> parseTransformAndColumn(ASTPtr object, size_t i)
{
    static const std::unordered_map<String, String> clickhouse_name_to_iceberg = {
        {"identity", "identity"},
        {"icebergBucket", "bucket"},
        {"icebergTruncate", "truncate"},
        {"toYearNumSinceEpoch", "year"},
        {"toMonthNumSinceEpoch", "month"},
        {"toRelativeDayNum", "day"},
        {"toRelativeHourNum", "hour"}
    };

    if (!object)
        throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid iceberg sort order expression");

    auto parse_function = [] (const ASTPtr & func_object) -> std::pair<String, String>
    {
        const auto * func = func_object ? func_object->as<ASTFunction>() : nullptr;
        if (!func)
            throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid iceberg sort order expression, expected a function");

        const String & clickhouse_name = func->name;
        const auto it = clickhouse_name_to_iceberg.find(clickhouse_name);
        if (it == clickhouse_name_to_iceberg.end())
            throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unsupported function {} for iceberg", clickhouse_name);

        const auto * args_list = func->arguments ? func->arguments->as<ASTExpressionList>() : nullptr;
        if (!args_list)
            throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid iceberg sort order function {}: arguments are missing", clickhouse_name);
        const auto & args = args_list->children;

        std::optional<size_t> arg;
        String column_name;

        if (args.size() == 1)
        {
            const auto * identifier = args[0] ? args[0]->as<ASTIdentifier>() : nullptr;
            if (!identifier)
                throw Exception(

Review comment (suggestion):
It is logical_error (we should not call this function if so)

Code after:
        else
        {
            auto partition_field = getPartitionField(partition_by, column_name_to_source_id, partition_iter);
            fields->add(partition_field);
        }
    }
    else
        partition_iter = 0;

    result->set(Iceberg::f_fields, fields);
    return {result, partition_iter};
}

static String parseColumnArgument(const ASTPtr & arg_ast, const String & clickhouse_name, const String & error_suffix)
{
    const auto * identifier = arg_ast ? arg_ast->as<ASTIdentifier>() : nullptr;
    if (!identifier)
        throw Exception(
            ErrorCodes::BAD_ARGUMENTS,
            "Invalid iceberg sort order function {}: {}",
            clickhouse_name, error_suffix);
    return identifier->name();
}

static std::pair<String, String> parseFunction(const ASTPtr & func_object)
{
    const static std::unordered_map<String, String> clickhouse_name_to_iceberg = {
            {"identity", "identity"},
            {"icebergBucket", "bucket"},
            {"icebergTruncate", "truncate"},
            {"toYearNumSinceEpoch", "year"},
            {"toMonthNumSinceEpoch", "month"},
            {"toRelativeDayNum", "day"},
            {"toRelativeHourNum", "hour"}
        };

    const auto * func = func_object ? func_object->as<ASTFunction>() : nullptr;
    if (!func)
        throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid iceberg sort order expression, expected a function");

    const String & clickhouse_name = func->name;
    const auto it = clickhouse_name_to_iceberg.find(clickhouse_name);
    if (it == clickhouse_name_to_iceberg.end())
        throw Exception(ErrorCodes::BAD_ARGUMENTS, "Unsupported function {} for iceberg", clickhouse_name);

    const auto * args_list = func->arguments ? func->arguments->as<ASTExpressionList>() : nullptr;
    if (!args_list)
        throw Exception(ErrorCodes::BAD_ARGUMENTS, "Invalid iceberg sort order function {}: arguments are missing", clickhouse_name);
    const auto & args = args_list->children;

    std::optional<size_t> arg;