Skip to content

Read a subcolumn of a Hive partition column from the path - #124392

Open
groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:hive-partition-subcolumn-from-path
Open

groeneai wants to merge 7 commits into
ClickHouse:masterfrom
groeneai:hive-partition-subcolumn-from-path

Conversation

@groeneai

@groeneai groeneai commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123718
Related: #123381

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 reading a subcolumn of a Hive partition column (for example key.null, key.size or a tuple element t.a) from the data file instead of the path: such queries failed with NOT_FOUND_COLUMN_IN_BLOCK or returned the file's values. Closes #123718.

Description

On 26.3 and 26.9, with use_hive_partitioning = 1 and t=(1,2)/data.parquet storing t = (5,5):

SELECT t, t.a FROM file('t=(1,2)/data.parquet', Parquet, 't Tuple(a Int64, b Int64), v Int64'); -- (1,2) 5, expected (1,2) 1
SELECT v, key.null FROM file('key=7/data.parquet', Parquet, 'v Int64, key Nullable(Int64)');    -- NOT_FOUND_COLUMN_IN_BLOCK (the file has only v)

prepareReadingFromFormat recognized a partition column only by its exact name, so key.null was requested from the format, which either has no key (partition columns are never read from the file) or reads the file's own key. Now a subcolumn of a partition column is taken from the path too: addPartitionColumnsToChunk builds the column from the path value and extracts the subcolumn, and the path-pruning blocks skip such entries.

Such a query passes no filter to the format (as when the format reads partition columns), so a conjunct on t.a cannot prune row groups on the file's values. Without a filter DAG, PREWHERE and row policy inputs must still be registered for the reader (FormatFilterInfo::initKeyConditionOnce; the hunk is identical to the one in #124124). A read that they or the top-K filter cut short already stays out of the count() cache since #123903.

The test covers file, url, s3, partition_strategy = 'hive', .null, .size, tuple elements, PREWHERE, row policies and the count cache after a filtered or top-K read. It fails on master and passes 50/50 randomized runs.


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

groeneai and others added 3 commits October 7, 2026 04:16
prepareReadingFromFormat classified a requested column as a Hive
partition column by exact name, so a subcolumn such as `key.null` or
`t.a` of a partition column was read from the data file: it either
failed with NOT_FOUND_COLUMN_IN_BLOCK (the file column is never read
for a partition column) or returned the file's value next to the
path's value of the column itself.

Classify a requested subcolumn of a partition column as a partition
column, and build it in addPartitionColumnsToChunk from the path value
of its storage column with IDataType::getSubcolumn. Path pruning does
not parse subcolumns, so they are skipped there, and the format gets no
filter when a partition subcolumn is requested, because the format
would evaluate it on the file's values.

Related: ClickHouse#123718

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A query requesting a partition subcolumn passes no format filter, so PREWHERE / row-level inputs are registered without a filter DAG and a reader-side filter keeps its row count out of the count cache; the hunks are shared with ClickHouse#124124 (initKeyConditionOnce) and ClickHouse#123903 (hasFilter, object-storage count cache).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Without a format filter DAG, `FormatFilterInfo::hasFilter` must still be true
while the top-K dynamic filter is armed: a top-K read that skips row groups
would otherwise store its short row count as the file's count. No other row of
05332 arms a top-K filter (they all request a partition subcolumn, which turns
it off), so add a `file()` read without a partition column: `ORDER BY v LIMIT 3`
over 10 row groups, then a cached `count()`. Master returns 100, the fix 1000.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work labels Oct 7, 2026
@groeneai

groeneai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review (click to expand)
Finding Verdict
⚠️ The top_k_filter term of hasFilter() was not exercised by the test (every count-cache row requests a partition subcolumn, which disarms top-K). AGREE, fixed: added a top-K read followed by a cached count() (round 1).
💡 hasFilter() does not include rows_to_read. DISAGREE: rows_to_read is set only by the lazy-rows source, which never writes the count cache; object storage guards it separately.
💡 The top-K and count-cache rows assert results only, so they would pass if top-K or the cache lookup declined. DISAGREE: on master the top-K row's cached count() returns 100 under the test's settings, which needs both a top-K-shortened read and a cache hit, so the rows fail on master.

@groeneai

groeneai commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT t, t.a FROM file('t=(1,2)/data.parquet', ...) with use_hive_partitioning = 1 returns (1,2) 5 on every run (26.3.42.3, 26.9.9.28, master); SELECT v, key.null ... always fails NOT_FOUND_COLUMN_IN_BLOCK. The test 05332 reproduces 28 rows deterministically.
b Root cause explained? prepareReadingFromFormat classified a requested column as a Hive partition column by exact name, so key.null / t.a went to columns_to_read; partition columns are dropped from the format header, so the format either had no key (NOT_FOUND_COLUMN_IN_BLOCK) or, after the empty-header refill of #123381 or via Parquet tuple-element reads, read the data file's own column. addPartitionColumnsToChunk could not produce a subcolumn either (it built column.type from the storage-name value).
c Fix matches root cause? Yes. The classification now resolves subcolumns of partition columns, addPartitionColumnsToChunk builds the storage column from the path and extracts the subcolumn, and the path-pruning blocks skip subcolumn entries. Such queries pass no format filter (a conjunct on t.a would otherwise be resolved from the file); PREWHERE / row-level inputs are registered without a filter DAG, and a reader-filtered row count is never cached.
d Test intent preserved / new tests added? New test 05332_hive_partitioning_subcolumn_of_partition_column (28 checked rows): file, url, s3, partition_strategy = 'hive', .null, .size, tuple elements on the Parquet and JSONEachRow paths, lazy materialization, format filter push-down, PREWHERE, row policies, and the count() cache for file and s3, including after a top-K read.
e Both directions demonstrated? Yes. Base efb815f65013: test FAIL (25 of 28 rows wrong or NOT_FOUND_COLUMN_IN_BLOCK); fix: PASS. Each part of the fix reverted on its own (10 mutation arms) turns the test red on the rows that part owns.
f Fix is general across code paths? Yes. The fix is in the shared code used by file, url, every object storage and their *Cluster workers (prepareReadingFromFormat, addPartitionColumnsToChunk, VirtualColumnUtils, FormatFilterInfo); the three count-cache writes all use hasFilter(). Verified for serialize_query_plan, s3Cluster and parallel replicas over s3.
g Fix generalizes across inputs (params/datatypes/wrappers)? Generic via the storage snapshot's subcolumn lookup and IDataType::getSubcolumn: Nullable .null, String .size, Tuple elements (native Parquet read and the widening path); filter push-down on and off, lazy materialization, PREWHERE, row policies.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change. Full partition columns are produced byte-identically; only queries that requested a partition subcolumn change (they failed or returned file values before).
i Invariants and contracts preserved? Values of every entry in hive_partition_columns_to_read_from_file_path come from the path; the format reads every PREWHERE / row-level input it evaluates with or without a filter DAG (with a DAG the order in initKeyConditionOnce is unchanged; FormatSharedInit.* and ParquetReaderPrewhere.* gtests pass); a row count reduced by a reader-side filter never enters the count cache.

Session id: cron:clickhouse-impl-self-slot-57:20261007-081400

@groeneai
groeneai requested review from al13n321 and alesapin October 7, 2026 09:13
@clickhouse-gh

clickhouse-gh Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [18b1299]

Summary: ✅


AI Review

Summary

The PR derives Hive partition subcolumns from path values and registers reader-side filter inputs even without a filter DAG. One reproducible PREWHERE input-registration defect remains. Consumer tracing covered the file, url, and object-storage sources, path pruning, query-plan serialization, lazy materialization, and filter/top-K consumers: the new subcolumn descriptors are materialized, preserved, or conservatively excluded as appropriate.

Findings

⚠️ Majors

  • src/Formats/FormatFilterInfo.cpp:319–320: Independent dotted physical columns are omitted from PREWHERE inputs. With schema key Nullable(Int64), v UInt64, `v.tag` UInt64, SELECT v, key.null FROM file('key=9/dotted.parquet', Parquet, ...) PREWHERE `v.tag` = 1 fails with NOT_FOUND_COLUMN_IN_BLOCK. buildKeyConditionInputs uses isColumnCovered, which incorrectly treats scalar v as covering the separate stored column v.tag; the reader therefore receives only v. On the PR's ARM binary, four fixture rows generated as (NULL, number, number % 2) should return (1, 0), (3, 0), but throw instead. Plain projection and the equivalent WHERE with optimize_move_to_prewhere = 0 succeed. This helper defect also reproduces without the Hive-subcolumn projection; it is a pre-existing limitation reached by the combination supported here. Resolve coverage using actual column ancestry and add a focused regression, or link an issue tracking the limitation.
Missing context / blind spots
  • ⚠️ The current CI workflow is still running, including the relevant stateless jobs. The report tool's green icons also cover pending jobs; they do not establish that the new stateless test passed on this head. Targeted local checks used the PR's ARM CI binary; the full new test requires the CI S3/HTTP services.
Final Verdict

⚠️ Request changes — fix or explicitly track the dotted-column PREWHERE limitation, and confirm the new stateless test passes on the current head.

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

clickhouse-gh Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 18b1299fa with master f30d7ec4f (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

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

Job report

groeneai and others added 2 commits October 7, 2026 14:08
With parallel replicas enabled and `automatic_parallel_replicas_mode = 0`,
`parallel_replicas_for_cluster_engines` turns `s3()` into `s3Cluster`, which
rejects an explicit PREWHERE with ILLEGAL_PREWHERE. That failed the test in
the ParallelReplicas stateless job. The two rows check the plain s3 read
path, so pin the setting to 0 on them only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The PR workflow run for 9270a54 was abandoned by the GitHub Actions
outage of 2026-10-07 and cannot be re-run from this account.

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

groeneai commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d65dcfd

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, which changes how Hive partition columns are read: the job was killed at its 9000 s limit at test 1140 of 1174, and every test that ran before the kill passed, so CIDB has only the job-level row. The same job-level error hit 67 pull requests and 13 master runs in 7 days #123849 (mine, open), which splits this job into 2 batches
PR rollup, red only because of the row above #123849 (the same)

All 149 check runs completed, Mergeable Check and CH Inc sync are green, and CIDB has no FAIL or ERROR test row on this head. The new test 05332_hive_partitioning_subcolumn_of_partition_column passed on every job that ran it, including Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel).

Session id: cron:our-pr-ci-monitor:20261008-060500

…olumn-from-path

# Conflicts:
#	src/Storages/HivePartitioningUtils.cpp
#	src/Storages/VirtualColumnUtils.cpp
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 5249e20

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 (amd_debug, sequential) / 05339_iceberg_top_k_query_condition_cache master breakage, not from this PR (it changes how Hive partition subcolumns are read): the test failed on all master commits from the #126987 merge 41d5f3406f9d until its revert, and the tested merge tree dd5cf0054e11 contains #126987 but not the revert #127378 (external, merged revert)
Stateless tests (amd_debug, distributed plan, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_asan_ubsan, azure, sequential, 2/2) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, AsyncInsert, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Stateless tests (arm_binary, s3 storage, DBReplicated, sequential) / 05339_iceberg_top_k_query_condition_cache same master breakage #127378 (external, merged revert)
Mergeable Check, PR praktika rollups of the rows above #127378 (the owner of the rows above)

CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261022-170010

@al13n321
al13n321 removed their request for review October 29, 2026 16:44
Comment on lines +319 to +320
if (!filter_actions_dag)
return;

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.

[Major] The input registration before this return still drops independent dotted physical columns. buildKeyConditionInputs calls isColumnCovered, which considers v.tag covered whenever keys contains v, even when v is a scalar and v.tag is a separate stored column. Consequently v.tag never reaches additional_columns.

Reproduced on this head's ARM binary:

INSERT INTO FUNCTION file('key=9/dotted.parquet', Parquet, 'key Nullable(Int64), v UInt64, `v.tag` UInt64')
SELECT NULL, number, number % 2 FROM numbers(4);

SELECT v, key.null
FROM file('key=9/dotted.parquet', Parquet, 'key Nullable(Int64), v UInt64, `v.tag` UInt64')
PREWHERE `v.tag` = 1
ORDER BY v
SETTINGS use_hive_partitioning = 1;

Expected (1, 0), (3, 0); actual: NOT_FOUND_COLUMN_IN_BLOCK, with Not found column v.tag in block. There are only columns: v. Projecting the dotted column and evaluating the same condition in WHERE with optimize_move_to_prewhere = 0 both succeed.

This is an existing helper defect, also reproducible without projecting key.null, reached by the Hive-subcolumn/PREWHERE combination supported here. Please distinguish actual subcolumn ancestry from name prefixes and add this regression case, or explicitly link an issue tracking the remaining limitation.

nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Nov 16, 2026
… reads

An explicit PREWHERE leaves its PREWHERE-only columns out of the format
header, so `FormatFilterInfo::buildKeyConditionInputs` adds them to
`additional_columns`, the extra columns the reader produces. Since ClickHouse#104435
(GeoParquet pruning) its `add_required` lambda skipped a name when
`isColumnCovered` found any dot-prefix of it in the header. For
`SELECT v ... PREWHERE `v.tag` = 1`, `v` is in the header, so `v.tag` was
taken for a subcolumn of `v`, never requested, and the Parquet reader threw
NOT_FOUND_COLUMN_IN_BLOCK when it evaluated PREWHERE. 26.7 checked the exact
name there and returned the rows.

PREWHERE and pushed-down row policy inputs are storage columns for every
storage that builds a `FormatFilterInfo` with them: File, URL and
ObjectStorage return top-level names from `supportedPrewhereColumns()` and
do not admit subcolumns (`supportedPrewhereColumnsIncludeSubcolumns()` is
false), so explicit PREWHERE, the move to PREWHERE and the row policy
pushdown never pass a subcolumn. Match them by exact name again. Keep
`isColumnCovered` for the `filter_actions_dag` (WHERE) loop in
`initKeyConditionOnce`: WHERE can name a real subcolumn (`t.a` with `t` in
the header), and requesting both from the Parquet reader is rejected as
COLUMN_QUERIED_MORE_THAN_ONCE.

This also covers stored columns whose names are valid subcolumn names of
the prefix column (`n.null` next to a Nullable `n`, `j.x` next to a JSON
`j`), which a type-aware prefix check would still misread.

Related: ClickHouse#124392 (comment)

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

This branch has not been deployed

No deployments
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-follow-up PR origin: groeneai's own out-of-scope finding during its PR work pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subcolumn of Hive partition column read from file instead of path

1 participant