Repository: ClickHouse/ClickHouse
File: src/Storages/HivePartitioningUtils.cpp (C++)

Code before:
    const std::string & path)
{
    const auto hive_map = parseHivePartitioningKeysAndValues(path);

    for (const auto & column : hive_partition_columns_to_read_from_file_path)
    {
        const std::string column_name = column.getNameInStorage();
        const auto it = hive_map.find(column_name);

        if (it == hive_map.end())
        {
            throw Exception(
                ErrorCodes::INCORRECT_DATA,
                "Expected to find hive partitioning column {} in the path {}."
                "Try it with hive partitioning disabled (partition_strategy='wildcard' and/or use_hive_partitioning=0",
                column_name,
                path);
        }

        auto chunk_column = column.type->createColumnConst(chunk.getNumRows(), convertFieldToType(Field(it->second), *column.type))->convertToFullColumnIfConst();
        chunk.addColumn(std::move(chunk_column));
    }
}

void sanityCheckSchemaAndHivePartitionColumns(
    const NamesAndTypesList & hive_partition_columns_to_read_from_file_path,
    const ColumnsDescription & storage_columns,
    bool check_contained_in_schema)
{
    if (check_contained_in_schema)
    {
        for (const auto & column : hive_partition_columns_to_read_from_file_path)
        {
            if (!storage_columns.has(column.name))
            {
                throw Exception(
                    ErrorCodes::BAD_ARGUMENTS,
                    "All hive partitioning columns must be present in the schema. Missing column: {}. "
                    "If you do not want to use hive partitioning, try `use_hive_partitioning=0` and/or `partition_strategy != hive`",
                    column.name);
            }
        }
    }

    if (storage_columns.size() == hive_partition_columns_to_read_from_file_path.size())
    {
        throw Exception(
            ErrorCodes::INCORRECT_DATA,
            "A hive partitioned file can't contain only partition columns. "
            "Try reading it with `use_hive_partitioning=0` and/or `partition_strategy != hive`");
    }

Review comment (suggestion):
JAS for code readability: let's split the function on two functions with better names and remove added parameter completely.

Code after:
    const NamesAndTypesList & hive_partition_columns_to_read_from_file_path,
    const std::string & path)
{
    const auto hive_map = parseHivePartitioningKeysAndValues(path);

    for (const auto & column : hive_partition_columns_to_read_from_file_path)
    {
        const std::string column_name = column.getNameInStorage();
        const auto it = hive_map.find(column_name);

        if (it == hive_map.end())
        {
            throw Exception(
                ErrorCodes::INCORRECT_DATA,
                "Expected to find hive partitioning column {} in the path {}."
                "Try it with hive partitioning disabled (partition_strategy='wildcard' and/or use_hive_partitioning=0",
                column_name,
                path);
        }

        auto chunk_column = column.type->createColumnConst(chunk.getNumRows(), convertFieldToType(Field(it->second), *column.type))->convertToFullColumnIfConst();
        chunk.addColumn(std::move(chunk_column));
    }
}

void sanityCheckSchemaAndHivePartitionColumns(
    const NamesAndTypesList & hive_partition_columns_to_read_from_file_path,
    const ColumnsDescription & storage_columns,
    bool check_contained_in_schema)
{
    if (check_contained_in_schema)
    {
        for (const auto & column : hive_partition_columns_to_read_from_file_path)
        {
            if (!storage_columns.has(column.name))
            {
                throw Exception(
                    ErrorCodes::BAD_ARGUMENTS,
                    "All hive partitioning columns must be present in the schema. Missing column: {}. "
                    "If you do not want to use hive partitioning, try `use_hive_partitioning=0` and/or `partition_strategy != hive`",
                    column.name);
            }
        }
    }

    if (storage_columns.size() == hive_partition_columns_to_read_from_file_path.size())
    {
        throw Exception(
            ErrorCodes::INCORRECT_DATA,
            "A hive partitioned file can't contain only partition columns. "
            "Try reading it with `use_hive_partitioning=0` and/or `partition_strategy != hive`");