Repository navigation
Description
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()orurl()withuse_hive_partitioning = 1andWHERE key = 9on a path likekey=9/data.parquet. - Expected
count(), min(key), max(key)of 10 9 9 but got 0 0 0. - Affects
file()andurl(), 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) addskeytoadditional_columns;Reader::prefilterAndInitRowGroups(Parquet/Reader.cpp:524) appends it toextended_sample_block, which resolves to the file'skeycolumn.- Min/max, bloom, page-index and dictionary filtering then reject every row group (all four must be off to get 10 rows).
Affected locations:
src/Storages/prepareReadingFromFormat.cpp:358—formatReadsHivePartitionColumnschecks onlyformat_headersrc/Storages/StorageFile.cpp:2608—ReadFromFilepushes the filter when the header lacks partition columnssrc/Storages/StorageURL.cpp:1776— same guard inReadFromURLsrc/Processors/QueryPlan/ReadFromObjectStorageStep.cpp:127— same guard inReadFromObjectStorageStep(not exercised)src/Formats/FormatFilterInfo.cpp:164— filter inputs absent from the header becomeadditional_columnssrc/Processors/Formats/Impl/Parquet/Reader.cpp:524—additional_columnsresolved against the file schema
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).
-- 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 = 1still 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
- Resolved by: Fix a filter on a Hive partition column pruning by the data file's column of the same name (revert of revert with a fix) #124991
- Merged into:
26.10.1.2107-master(included in26.10and later) - Backported to:
26.9.17.9,26.8.25.15
Activity
Do not evaluate a filter on a Hive partition or virtual column agains…