Skip to content

Hive partition filter wrongly prunes Parquet row groups by same-name file column #123717

Description

@clickgapai

Describe what's wrong

  • A WHERE filter on a Hive partition column drops all rows when the Parquet file also has a column with that name.
  • Triggered via file() or url() with use_hive_partitioning = 1 and WHERE key = 9 on a path like key=9/data.parquet.
  • Expected count(), min(key), max(key) of 10 9 9 but got 0 0 0.
  • Affects file() and url(), and silently loses rows whenever file data under the partition differs from the path value.

Root cause: formatReadsHivePartitionColumns only checks format_header, so when the file also stores a column named like the partition, the filter on that column is pushed into the Parquet reader. FormatFilterInfo::initKeyConditionOnce then adds it to additional_columns, and Reader::prefilterAndInitRowGroups matches it against the file's own column, so min/max, bloom, page-index and dictionary filtering reject every row group.

Analysis details (evidence, affected locations, impact)

Why we believe this is a bug: - ReadFromFile::initializePipeline (StorageFile.cpp:2607) passes filter_actions_dag to FormatFilterInfo unless formatReadsHivePartitionColumns (prepareReadingFromFormat.cpp:358) finds a partition column in format_header. With s in the header it does not, so key = 9 is pushed.

  • FormatFilterInfo::initKeyConditionOnce (FormatFilterInfo.cpp:164-169) adds key to additional_columns; Reader::prefilterAndInitRowGroups (Parquet/Reader.cpp:524) appends it to extended_sample_block, which resolves to the file's key column.
  • Min/max, bloom, page-index and dictionary filtering then reject every row group (all four must be off to get 10 rows).

Affected locations:

Impact: Silent row loss for a WHERE on a Hive partition column over Parquet whenever the data files store a column of the same name with values that differ from the path. Reached through file() and url() (exercised). Present since 26.8; #123381 (where this was found; not confirmed as the cause) leaves it in place for every query that reads a non-partition column, including its own count() shape once the fallback picks a non-partition column.

Does it reproduce on most recent release?

Confirmed on master (4127c65654d0); not checked on a release.

How to reproduce

Needs use_hive_partitioning = 1, optimize_count_from_files = 0, and input_format_parquet_filter_push_down = 1, with a Parquet file under key=9/ whose key column holds different values (1000..1009).

▶ Run on ClickHouse Fiddle

-- Tag no-fasttest: depends on Parquet

-- A filter on a hive partition column must use the value from the path, also when the Parquet file has a column of that name.

INSERT INTO FUNCTION file(currentDatabase() || '/05320/key=9/data.parquet') SELECT toString(number) AS s, 1000 + number AS key FROM numbers(10) SETTINGS engine_file_truncate_on_insert = 1;

SET use_hive_partitioning = 1;
SET optimize_count_from_files = 0;
SET input_format_parquet_filter_push_down = 1;

SELECT count(), min(key), max(key) FROM file(currentDatabase() || '/05320/key=9/data.parquet');
SELECT count(), min(key), max(key) FROM file(currentDatabase() || '/05320/key=9/data.parquet') WHERE key = 9;

Verified: this block reproduces on current master (4127c65654d0) when pasted as is.

Expected behavior

A WHERE filter on a Hive partition column should use the value from the path, not the file's same-name column.

Expected output of the reproducer above:

10	9	9
10	9	9

Error message and/or stacktrace

The filter is pushed down into Parquet row-group pruning using the file's own column values, eliminating every row group.

Actual output of the reproducer above on master (4127c65654d0):

10	9	9
0	0	0
Suggested fix

Key the guard on the filter, not the header: before building FormatFilterInfo, drop the conjuncts that read a column of info.hive_partition_columns_to_read_from_file_path (VirtualColumnUtils::splitFilterDagForAllowedInputs over the file columns), or pass nullptr when any filter input is a partition column. Splitting keeps row-group pruning for the other conjuncts; nullptr is simpler but loses it. Either subsumes formatReadsHivePartitionColumns on the filter path.

Additional context

Open risks:

  • s3() / azureBlobStorage() / hdfs() not exercised (no endpoint locally); same guard and reader.
  • ORC was not affected in the same probe (input_format_orc_filter_push_down = 1 still returned 10).

Found during automated review of PR #123381; the bug predates that PR (it reproduces on the master build just before it merged), so the introducing change is not identified yet. Severity P2 · Finding h_pr123381_001

Version info

Activity

  1. added
    comp-table-functions
    on Oct 3, 2026
  2. added a commit that references this issue on Oct 9, 2026
    d035f9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai_p2comp-table-functions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions