Skip to content

Use the table's format settings in the Hive partition filter of stored file-like tables - #131571

Merged
PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:hive-path-filter-table-format-settings
Nov 16, 2026
Merged

PedroTadim merged 3 commits into
ClickHouse:masterfrom
groeneai:hive-path-filter-table-format-settings

Conversation

@groeneai

@groeneai groeneai commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131256
Related: #131256 (comment)

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a WHERE on a Hive partition column of a File, URL, S3, AzureBlobStorage or HDFS table skipping files whose rows match it, or failing with CANNOT_PARSE_BOOL, when the table's format settings (for example bool_true_representation in its SETTINGS) change how the column's values are parsed.

Description

On 26.10.2.103 (and 26.8.34.13), a table ENGINE = File(JSONEachRow, 'd/b=si/data.jsonl') SETTINGS bool_true_representation = 'si' reads its row with b = true, but SELECT * FROM t WHERE b fails with CANNOT_PARSE_BOOL. With bool_true_representation = 'false', bool_false_representation = 'true' over d/b=false/data.jsonl, SELECT count() FROM t WHERE b returns 0 instead of 1.

A stored table reads a Hive partition column with its own format settings, but every iterator that runs the _path / _file / partition-column pre-filter passed std::nullopt to VirtualColumnUtils::getFilterByPathAndFileIndexes, so the filter converted the value with the query's settings. That function already takes the settings; only the readers passed them.

The change passes the reader's std::optional<FormatSettings> to StorageFileSource::FilesIterator, StorageURLSource::DisclosedGlobIterator and, for object storage, to createFileIterator, GlobIterator and the deferred KeysIterator, from ReadFromObjectStorageStep and from the initiator of a parallel-replicas read. The new parameters default to std::nullopt, so table functions, fileCluster and urlCluster, which have no table settings, are unchanged. Data lakes do not filter on Hive columns; S3Queue builds its path filter without them. Most of the diff replaces /*format_settings=*/std::nullopt or extends a signature; it splits by storage family if preferred.

The test has one case per changed call site: File, URL, S3 key, brace expansion, glob, the deferred GLOBAL IN filters and parallel replicas. The deferred filter in FilesIterator::next gets the same settings, but I found no query that reaches it for a stored File table (its sets are built in applyFilters), so the test has no case for it. The test fails on master and passes with the fix (50/50 randomized); 25 related Hive and path-filter tests pass.


Workflow [PR]
Sync PR [sync-upstream/pr/131571]

Version info

  • Merged into: 26.11.1.2468-master (included in 26.11 and later)

groeneai and others added 2 commits November 14, 2026 07:40
…e-like tables

A stored `File`, `URL`, `S3`, `AzureBlobStorage` or `HDFS` table reads a Hive
partition column with its own format settings (global settings plus its
`SETTINGS` clause), but the `_path` / `_file` / Hive pre-filter converted the
partition value with the query's settings: every iterator passed
`std::nullopt` to `VirtualColumnUtils::getFilterByPathAndFileIndexes`, whose
`format_settings` parameter (added in bb7556a) was only ever threaded
into the reader. When the two differ, the filter computes a different value
than the column holds, so `WHERE` on the column skips files whose rows match
it (e.g. `bool_true_representation = 'false'`) or fails with
`CANNOT_PARSE_BOOL` on a value only the table's settings can parse.

Pass the reader's `std::optional<FormatSettings>` into the iterators that run
the pre-filter: `StorageFileSource::FilesIterator` (immediate and deferred),
`StorageURLSource::DisclosedGlobIterator`, and for object storage
`createFileIterator` (brace expansion and explicit keys, immediate and the
deferred `KeysIterator`) and `GlobIterator`, from `ReadFromObjectStorageStep`
and from the initiator of a parallel-replicas read
(`StorageObjectStorageCluster::getTaskIteratorExtension`). The new parameters
default to `std::nullopt`, so table functions, `fileCluster` and `urlCluster`,
which have no table format settings and already agree, are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `file, GLOBAL IN` query takes the same immediate filter in the
`FilesIterator` constructor as the plain `file` query: `ReadFromFile`
builds its `GLOBAL IN` sets in `applyFilters`, before plan optimization
moves the subquery plans away, so the deferred filter in
`FilesIterator::next` is not reached from a stored `File` table.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 2 findings) and my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test would still pass with a no-op path filter; the swapped true/false direction and the parallel-replicas plan are not asserted DISAGREE Each case fails on master and when its own call site is reverted (three revert groups, each case fails exactly in its group). A swapped-representation case would fail under the same reverts. Pruning itself is covered by existing tests (03231, 04669). Reverting only the cluster call fails the parallel-replicas case and not plain s3, so that case takes the cluster path.
2 ⚠️ In the ParallelReplicas CI profile the local S3 cases take the cluster path DISAGREE Both paths are fixed and return the same rows. The local path stays covered in every other job. The same setup (04669, 04627) is green in ParallelReplicas jobs.
3 💡 src diff (+50/-27, 8 files) is larger than a minimal PR noted Mostly 1:1 replacements of std::nullopt and appended parameters. It splits by storage family if preferred.
4 💡 No test case for the deferred filter in FilesIterator::next noted Stated in the description. No stored File query I found reaches it.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261114-083001

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @nikitamikhaylov, could you review this? The Hive partition pre-filter of stored File, URL and object storage tables converted partition values with the query's format settings while the reader used the table's, so WHERE on a partition column skipped matching files or threw CANNOT_PARSE_BOOL; the iterators now pass the reader's format settings to getFilterByPathAndFileIndexes.

@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [326c3e7]

Summary: ✅


AI Review

Summary

The Hive partition path filters now use the reader's FormatSettings for stored File, URL, and object-storage tables, including deferred filters and object-storage parallel replicas. No actionable findings in the current diff or affected call paths. The added regression test passed all 50 targeted CI runs at 2bcccf5b166a6747a38cc767b118eadb5ae78207; CI for the current head, 326c3e76026d81d8759321fc6c3cd053c3381cd9, remains pending. No local tests were run because this checkout has no built ClickHouse binary.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Nov 14, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 326c3e760 with master 491b6e935 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 325f338e7; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

58 translation units recompiled, 762 s compile time in total, 58 of them have a recent master baseline.

Job report

@PedroTadim PedroTadim self-assigned this Nov 15, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai The description says S3Queue doesn't filter on Hive columns, but with use_hive_partitioning it does. StorageObjectStorageQueue.cpp:437 takes the partition columns from the path, and ObjectStorageQueueSource.cpp:255 passes them to filterByPathOrFile, which still uses the query's format settings. So an S3Queue table with use_hive_partitioning = 1 and, for example, bool_true_representation = 'si' should hit the same CANNOT_PARSE_BOOL (or skip files) as the tables fixed here. Could you pass its format settings there too, the way the StorageURL call site now does, or say why it can't be reached?

@groeneai

Copy link
Copy Markdown
Collaborator Author

It can't be reached: the S3Queue path filter never converts a Hive value.

  • ObjectStorageQueueSource.cpp:162 builds the filter DAG without the Hive columns (createPathAndFileFilterDAG(predicate_, virtual_columns, context_)), and the queue's virtual columns are only the common ones (StorageObjectStorageQueue.cpp:471). So a condition on a partition column is split off before :255, where getFilterByPathAndFileIndexes converts only the columns the filter reads. Only a direct SELECT passes a predicate; the streaming path passes nullptr (StorageObjectStorageQueue.cpp:1063).
  • Measured on master, S3Queue('.../b=*/data.jsonl', JSONEachRow) SETTINGS use_hive_partitioning = 1, bool_true_representation = 'si', bool_false_representation = 'no' over b=si/ and b=no/: WHERE b AND _path LIKE '%/b=%' logs Filtered files: 2 -> 2 with no error, WHERE _path LIKE '%/b=si/%' logs 2 -> 1, and through a materialized view b=si reads as true. The same WHERE b on an S3 table with these settings fails with CANNOT_PARSE_BOOL (the case fixed here).

I reworded that sentence of the description.

The probe found a different bug: a direct SELECT from S3Queue does not take the Hive columns from the path at all, because prepareReadingFromFormat at StorageObjectStorageQueue.cpp:776 gets no Hive parameters (the streaming path at :1095 passes them). So k of k=abc/data.jsonl reads as ''. It is in the reader, not the filter, so I will fix it in a separate PR and link it here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

The fix for the direct SELECT from S3Queue not taking the Hive columns from the path is #131975.

@clickhouse-gh clickhouse-gh Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review approves this commit, see the AI Review comment.

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 16, 2026
Merged via the queue into ClickHouse:master with commit 76d313e Nov 16, 2026
192 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants