Skip to content

Fix filtering and reading a Hive partition column that some paths of a glob do not have - #125024

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-hive-partition-column-missing-from-path
Oct 21, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-hive-partition-column-missing-from-path

Conversation

@groeneai

@groeneai groeneai commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

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):

Fixed SIZES_OF_COLUMNS_DOESNT_MATCH and LOGICAL_ERROR when a file, url, s3, azureBlobStorage or hdfs glob matches paths that do not all contain a Hive partition column: a filter on _path or _file now works, and filtering on or reading such a column fails with INCORRECT_DATA naming the path. The Hive partition columns of a table created with use_hive_partitioning = 1 are now also read when the query runs with use_hive_partitioning = 0.

Description

On 26.8.18.2, SELECT x FROM file('d/*/a.csv', CSV, 'x UInt8') WHERE _file = 'a.csv' over d/key=1/a.csv and d/b/a.csv fails with SIZES_OF_COLUMNS_DOESNT_MATCH, and ... WHERE key = 1 throws LOGICAL_ERROR (Expected the argument №1 ('key' of type Int64) to have 2 rows, but it has 1), an abort in debug builds. Found by AST fuzzer (amd_debug, targeted, old_compatibility), STID 2959-3490 (the same LOGICAL_ERROR from VirtualColumnUtils::getFilterByPathAndFileIndexes): https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123788&sha=88a61f2ec658a76a0060fdac4f9ce522fa75f1c2&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%2C%20old_compatibility%29

Hive partition columns are taken from one sample path. The _path/_file pre-filter then appended a value only for the keys a path has, so a path without key left the key column one row short. The virtual-column reader likewise skipped a missing key (and every key when use_hive_partitioning = 0 at query time), so the chunk had fewer columns than its header.

Now both take each Hive value from the path through one helper that throws the existing INCORRECT_DATA error the schema Hive reader already used, and the pre-filter materializes only the columns its expression reads. Paths that carry every key behave exactly as before. A Hive column named _path or _file (listed in the structure) is no longer used by the pre-filter, which put the path or the file name there (LOGICAL_ERROR on master).

Out of scope: url takes Hive columns from the whole sample URI, query string included, while it reads them from the URI path. That is how the fuzzer query reached the filter, and it now fails with INCORRECT_DATA.

Validation: the new test fails on master on every assertion and passes with the fix (100/100 randomized runs); related stateless and Hive integration tests show no difference from master.


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

Version info

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

groeneai and others added 2 commits October 10, 2026 00:45
…a glob do not have

Hive partition columns of a file-like table are fixed from one sample
path, but the `_path`/`_file` pre-filter and the virtual-column reader
materialize them for every other path. The pre-filter appended a value
only for the keys a path carries, so a path without the key left that
column one row short: `checkFunctionArgumentSizes` threw LOGICAL_ERROR
when the predicate read the column, `IColumn::filter` threw
SIZES_OF_COLUMNS_DOESNT_MATCH when it did not. The reader silently
skipped a missing key (and every key when `use_hive_partitioning = 0`
at query time), leaving the chunk a column short of its header.

Both now take the value of every Hive column from the path through
`HivePartitioningUtils::getPartitionValueFromPath`, which throws the
INCORRECT_DATA error the schema Hive reader already raised (message
unchanged, moved into the helper). The pre-filter materializes only the
columns its split expression reads, so a filter on `_file` never needs
a Hive value, and the path is parsed only when a Hive column is needed.

Found by the AST fuzzer (STID 2959-3490): `url` derives Hive columns
from the whole sample URI, query string included, while it filters on
the URI path, so the fuzzer's `x(?i)/.../key=9/data.orc` reached the
pre-filter with a path that has no `key`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
State the required-columns filter comment as a domain invariant instead of design narration.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 10, 2026
@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; 1 full pass, no fix round needed).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test asserts only INCORRECT_DATA, not that the message names the path without the key DISAGREE The message is the existing one, moved unchanged; existing tests of it (03363_hive_style_partition.sql) also assert only the code. A caller that parsed another path would find the key and not throw, so the test would fail. Locally the new errors name the path that lacks the key (/b/a.csv, x( for the fuzzer query).
2 💡 The shared message suggests use_hive_partitioning = 0, which does not help a table whose Hive columns were fixed at CREATE, and misses a closing parenthesis noted, not blocking Existing text, moved unchanged.

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

Session id: cron:clickhouse-review-slot-9:20261010-004900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local over d/key=1/a.csv + d/b/a.csv, or url('http://127.0.0.1:1/{key=1/a,b/a}.csv', ...) (no connection needed): every shape fails on every run. The fuzzer's query with its unmasked URL x(?i)/05316/c=1/key=9/data.orc gives the CI message exactly.
b Root cause explained? Hive columns come from one sample path. The _path/_file pre-filter appended a value only for keys a path has, so the block was ragged (LOGICAL_ERROR in checkFunctionArgumentSizes, or SIZES_OF_COLUMNS_DOESNT_MATCH); the virtual-column reader skipped a missing key, so the chunk was a column short (LOGICAL_ERROR in OutputPort).
c Fix matches root cause? Yes. Both sites take each Hive value from the path through one helper that throws the existing INCORRECT_DATA (already used by the schema Hive reader); the pre-filter materializes only the columns its expression reads. No guard at the throw sites.
d Test intent preserved / new tests added? New 05353_hive_partitioning_path_without_partition_key.sql: url and s3 globs, schema and inferred Hive columns, _file filter, reader, and a table read with use_hive_partitioning = 0. Every assertion fails on master.
e Both directions demonstrated? Yes, base and fix built from the same tree (Build IDs differ): base aborts or returns Code: 9 on every assertion, fix matches the reference; 100/100 randomized runs (50 sequential, 50 parallel).
f Fix is general across code paths? Both functions are shared by file, url, s3, azureBlobStorage, hdfs, the *Cluster variants, queues and data lakes, so one change covers all of them; the schema Hive reader now uses the same helper.
g Fix generalizes across inputs (params/datatypes/wrappers)? Value parsing is unchanged (same deserializeWholeText / convertFieldToType and Hive format settings); tested with schema-typed UInt8 and inferred Int64 columns, Nullable structure in the fuzzer shape, single and globbed paths.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or default change. Only queries that threw LOGICAL_ERROR or SIZES_OF_COLUMNS_DOESNT_MATCH change outcome; paths that carry every key give identical results.
i Invariants and contracts preserved? Every pre-filter block column gets exactly one value per path or the query throws before the block is used; every requested virtual column gets a chunk column or the query throws. No locking or concurrency change.

Session id: cron:clickhouse-impl-slot-4:20261009-222400

@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [4896111]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, azure, sequential) ERROR

AI Review

Summary

This PR fixes the two broken Hive-partition paths consistently: the listing-time _path/_file filter now materializes only the Hive columns the predicate actually reads, and both the filter path and the post-read virtual/partition-column path now fail with INCORRECT_DATA when a matched object is missing a required Hive key. The added stateless coverage exercises the main regression shapes called out in the PR (url prefiltering, s3 reads and filters, shadowing of _path/_file, and querying a table created with use_hive_partitioning = 1 while running with use_hive_partitioning = 0). I did not find a remaining contract violation in the current diff.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 10, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Oct 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 489611167 with master d741c9860 (stripped binary size, per-symbol sizes and ThinLTO time; 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

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

Job report

groeneai and others added 2 commits October 10, 2026 06:02
With parallel replicas the `s3` read becomes `s3Cluster`, and each replica
runs its part of the query in its default database. There `currentDatabase()`
in `filename` names another prefix, the replica's glob lists nothing, so `a`
is not a column and the query fails with UNKNOWN_IDENTIFIER instead of
INCORRECT_DATA. `{CLICKHOUSE_DATABASE:String}` is substituted on the
initiator, so all replicas list the same files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The path filter block fills `_path` and `_file` with the object path and
the file name. A Hive column with one of these names, listed in the
structure so that it shadows the virtual column, landed in the same block,
so the filter compared the path or the file name with its value and
dropped matching files: the query returned no rows (on master it is a
LOGICAL_ERROR). Such a column is now left out of the path filter and is
filtered after it is read from the path.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 4896111

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_asan_ubsan, azure, sequential) job timeout, not from this PR: the job was stopped at its 9000 s limit after 1163 of 1180 tests, with no failed test (the same job errored on 40 other PRs today) #123849 (mine, open)
PR praktika rollup of the row above #123849 (mine, open)

Session id: cron:our-pr-ci-monitor:20261010-120003

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All good.

@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 21, 2026
Merged via the queue into ClickHouse:master with commit 9de8a78 Oct 21, 2026
161 of 163 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@groeneai @alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

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-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding 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.

4 participants