Skip to content

Fix reading Iceberg tuple elements from data files written before a schema change - #125439

Open
groeneai wants to merge 10 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-tuple-element-schema-change
Open

groeneai wants to merge 10 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-tuple-element-schema-change

Conversation

@groeneai

@groeneai groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125252
Closes: #128304

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 NOT_FOUND_COLUMN_IN_BLOCK when reading a tuple element (e.g. s.a) of an Iceberg table from data files written before a schema change such as ALTER TABLE ... ADD COLUMN.

Description

On 26.8.18.2 (and 26.9.16.11, as reported in #125252), after ALTER TABLE t ADD COLUMN extra Nullable(Int64) on an Iceberg table, SELECT id, s.a FROM t fails with Not found column or subcolumn s.a in block (NOT_FOUND_COLUMN_IN_BLOCK) for data files written before the change, while SELECT id, s works.

For Parquet, filterTupleColumnsToRead turns s.a into a flat column that the reader produces directly. For a file written under an older schema id, StorageObjectStorageSource::createReader replaces the reader header with the file's full schema, so the reader and the Iceberg schema transform return the whole s and the final ExtractColumnsTransform cannot find s.a.

On that path, requested columns that the block lacks but that are subcolumns of a column it has are now extracted with createSubcolumnsExtractionActions. The block carries the current schema's names at that point, so an element resolves by its current name, also after RENAME COLUMN. Files read with their own header are unchanged, and a name that resolves to nothing still fails as before. Paimon field-id reads of files written before a top-level rename take this path too, so the extraction master runs for them at the end of createReader had nothing left to do and is removed.

The new test reads a Nullable element, a nested element, an Array(Tuple) element, a WHERE on an element, a row policy on an element, a PREWHERE on a top-level column with an element selected, the icebergLocal table function and an element after RENAME COLUMN, each from an old-schema file next to a current-schema one, and an element of a renamed Paimon ROW column, selected and in a row policy. It fails on master and passes with this change (50 randomized runs, also with parallel replicas). DROP COLUMN and MODIFY COLUMN (type promotion) failed the same way and are fixed as well.


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

…hema

For Parquet, `filterTupleColumnsToRead` turns a requested tuple element such
as `s.a` into a flat column with name-in-storage `s.a`, which the native reader
produces directly. For a data file whose schema id differs from the current one
(after ADD/DROP/RENAME/MODIFY COLUMN by any writer) `createReader` replaces the
reader header with the file's full schema, so the reader and the Iceberg schema
transform produce whole top-level columns (`s`) and the final
`ExtractColumnsTransform` failed with NOT_FOUND_COLUMN_IN_BLOCK.

On that branch, extract every requested name-in-storage that the block lacks
but that is a subcolumn of a column the block has, using
`createSubcolumnsExtractionActions`. The block carries the current schema's
names at that point, so elements resolve by the current name (also after
RENAME COLUMN). Files read with their own header are untouched, and a name
that resolves to nothing still fails as before.

Closes ClickHouse#125252

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 12, 2026
@groeneai

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

Pre-publication review: an own cold review plus an independent model (engine: codex; 0 findings). Own review: 2 nits, both refuted by code reading.

# Sev Finding Verdict Evidence / action
1 💡 An explicit PREWHERE on the whole parent tuple could drop it before the extraction DISAGREE The same PREWHERE DAG trims the header for every file, so current-schema files would lose s.a the same way; not a schema-change case. Auto-moved PREWHERE keeps its inputs (measured green)
2 💡 No test arm for an element of a tuple column added after the file was written DISAGREE The schema transform materializes the default parent, so the extraction sees an ordinary Tuple column, which the existing arms already cover

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

Session id: cron:clickhouse-review-slot-10:20261012-140800

@groeneai

groeneai commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The script from #125252 in clickhouse local fails with NOT_FOUND_COLUMN_IN_BLOCK on every run on master and on the 26.8.18.2 release image.
b Root cause explained? filterTupleColumnsToRead makes s.a a flat column for Parquet; for a file with an older schema id createReader reads the file's full schema instead, so the block has s but not s.a when ExtractColumnsTransform runs.
c Fix matches root cause? Yes. The missing elements are extracted from their parent on the schema-changed path only; ExtractColumnsTransform and the native element read are untouched.
d Test intent preserved / new tests added? New test 05366_iceberg_tuple_element_after_schema_change.
e Both directions demonstrated? Yes. The test fails on a base-binary server (Code 10) and passes on the fix; each old-file query fails on base one by one.
f Fix is general across code paths? Cluster and parallel-replica reads use the same createReader (fail on base, pass with the fix). Paimon field-id reads take this path too since f16a898, covered by the test; DeltaLake and Hudi do not.
g Fix generalizes across inputs (params/datatypes/wrappers)? Nullable, nested and Array(Tuple) elements, a tuple read together with its element, WHERE, the table function, RENAME, DROP and MODIFY COLUMN. ORC tables were not affected.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; an error becomes the correct result.
i Invariants and contracts preserved? Every requested column is in the block given to ExtractColumnsTransform; other columns pass through unchanged and no rows are added or removed.

Session id: cron:clickhouse-impl-slot-6:20261012-131700

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [819ea5a]

Summary: ❌

job_name test_name status info comment
Parser memory check DROPPED
Storage memory check DROPPED
Build profile diff DROPPED

AI Review

Summary

Restores tuple-element reads from older-schema Iceberg files by extracting requested elements after schema transformation and before fallback filters. Includes filter-only inputs, preserves Paimon extraction, and adds focused stateless regression coverage. No unresolved findings remain at commit 819ea5a89658953d42b1e361cb0d34684cc8a361; the previous filter-ordering finding is addressed.

Missing context / blind spots
  • ⚠️ No local ClickHouse binary or build is available, so I could not independently rerun the regression. Runtime evidence is the author's reported before/after validation; a CI result for 05616_data_lake_tuple_element_after_schema_change at this head would independently confirm it.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 12, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9962671a3 with master 8a8d2e477 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4ce893869; 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

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 587ab9c

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
Integration tests (arm_binary, 1/4) / test_storage_delta/test.py::test_writes_timestamp_ntz_annotation_nested not from this PR: the Spark 4.0 runner of #117198 broke this test on master (red on master from 13:32Z to 16:18Z, green again after the revert). This run was created at 14:36Z, so the tested tree contains #117198 but not the revert merged at 16:45Z #125455 (external, merged)
Integration tests (arm_binary, 1/4) / test_storage_delta/test_writes_interop.py::test_write_to_table_with_unsupported_writer_feature_is_rejected same cause as the row above #125455 (external, merged)
Mergeable Check, PR praktika rollups of the rows above #125455 (external, merged)

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

Session id: cron:our-pr-ci-monitor:20261012-220018

@PedroTadim

Copy link
Copy Markdown
Member

@scanhex12 I leave it to you

fm4v added 3 commits November 1, 2026 11:13
…ema-changed path

The extraction of tuple elements that `filterTupleColumnsToRead` made flat columns ran after the fallback `FilterTransform`s, so an explicit `PREWHERE` (or a row policy) on an element of a data file written under an older schema still failed with `NOT_FOUND_COLUMN_IN_BLOCK`: the stripped filter is replayed after the schema transform and takes the flat name as input, and `requested_columns` is post-`PREWHERE` and does not list a column consumed by a filter only.

Move the extraction to right after the schema transform and extract the inputs of the stripped filter DAGs as well. The test now covers an element used by an explicit `PREWHERE` only, by `PREWHERE` together with the select list, by a row policy, and by `PREWHERE` after `RENAME COLUMN`.

Review threads: ClickHouse#125439 (comment) and ClickHouse#125439 (comment)
qoega pushed a commit to qoega/ClickHouse that referenced this pull request Nov 7, 2026
…eld-id reads

A file read under its own names yields whole columns, while `filterTupleColumnsToRead` asks
for a tuple element (`s.y`) as a flat column, so `SELECT s.y` on a file written before a
top-level rename threw NOT_FOUND_COLUMN_IN_BLOCK. Extract the requested elements after the
schema transform, as ClickHouse#125439 does for Iceberg (gated to Paimon objects here).

Fields inside a ROW are still matched by name: after a nested rename, or a nested drop and
re-add under the same name, an older file returned NULL for the renamed field or the dropped
field's values. The schema mapping now compares nested field ids and names (through ARRAY,
MULTISET and MAP) and refuses such a file with NOT_IMPLEMENTED and the recovery text of
ClickHouse#127816. The docs say that only top-level columns are matched by field id.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A tuple element in PREWHERE is rejected at analysis for object storage
(`Code: 182 ... does not support column s.a in PREWHERE`, ILLEGAL_PREWHERE):
`StorageObjectStorage` does not override `supportedPrewhereColumnsIncludeSubcolumns`,
so `CollectTableExpressionData` refuses `s.a`, `s.b`, `s.c.x` and `r.a`. The
arms that put an element in PREWHERE therefore failed in every stateless job.

The stripped PREWHERE that is replayed after the schema transform of the
old-schema data file stays covered with a PREWHERE on `id`: with `s.a`
selected, under the row policy on `s.a`, and with `r.a` selected after
RENAME COLUMN. The Nullable element is filtered in WHERE instead, and the
duplicate of the earlier `WHERE s.a = 20` arm is dropped. Each changed arm
fails with NOT_FOUND_COLUMN_IN_BLOCK on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PedroTadim PedroTadim removed their assignment Nov 9, 2026
@PedroTadim

Copy link
Copy Markdown
Member

🕵️ @groeneai

The fix looks right to me. On the schema-changed path the reader gets the file's full schema, so a tuple element that filterTupleColumnsToRead made a flat column (s.a) is missing. The new block extracts it right after the schema transform and before both fallback FilterTransforms, and it also extracts the elements that only the stripped row policy or PREWHERE use. Because it runs after the transform, RENAME COLUMN and type promotions already apply. createSubcolumnsExtractionActions skips names already in the block, so a file without this problem is unaffected.

Since the last merge of master, Paimon field-id reads take this path too: reads_file_under_own_names (f16a898) needs an initial schema, so it implies schema_changed. Two things follow:

  • The extraction master added at the end of createReader for reads_file_under_own_names now always finds its elements already present, so it never does anything. It can be removed, unless I'm missing a case where it still applies.
  • A Paimon row policy on a ROW field should now work too, since the element is extracted before the fallback filter. Can a Paimon arm in the test show this? The validation note (item f) still says Paimon never takes this path.

Nit: many tests already use the 05366 prefix. tests/queries/0_stateless/add-test assigns the next free number.

groeneai and others added 2 commits November 9, 2026 15:48
A Paimon file read under its own names has an initial schema, so it takes the schema-changed
path, whose extraction after the schema transform already produces every requested element.
The one at the end of `createReader` (f16a898) found them present and did nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Paimon table renames its `ROW` column after the first commit, so the first file is read under
its own names; `r.a` is selected and used by a row policy. `05366` is taken by many tests, so the
test is now `05616` (the next free number, as `add-test` assigns it).

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

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, all three are done:

  • Removed the extraction at the end of createReader in cbedac3. No case is left: reads_file_under_own_names implies schema_changed, the block after the schema transform extracts a superset of those names, and a Paimon read has no fallback filter between the two (see below).
  • Paimon case in d0b5a1c: a small fixture (written with pypaimon, generator in its README) whose ROW column s is renamed to r after the first commit, so the first file is read under its own names. The test selects r.a, r.b and adds a row policy USING r.a >= 20. One correction: that policy already worked on master, because a Paimon read never gets a pushed-down policy (DataLakeConfiguration::supportsPrewhere() is true only for Iceberg, so the policy stays a Filter step above ReadFromObjectStorage). So the case guards the removal: with the remaining extraction disabled, SELECT r.a fails with NOT_FOUND_COLUMN_IN_BLOCK. Item f of the validation note is corrected.
  • The test is now 05616_data_lake_tuple_element_after_schema_change, the number add-test assigns.

50/50 randomized runs pass; master still fails the Iceberg queries with Code 10.

Drop the checked-in data_minio/paimon_row_rename fixture: the test now writes
the two schema files, the snapshot, the manifest list, the manifest and the two
Parquet data files itself (the first one under schema 0, with the ROW column
still named s), like 05301_paimon_manifest_path_traversal does.

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-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

4 participants