Skip to content

Reject an Iceberg INSERT that writes a column the table no longer has, for every format - #126768

Merged
alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-insert-dropped-renamed-column-all-formats
Nov 13, 2026
Merged

alexey-milovidov merged 4 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-insert-dropped-renamed-column-all-formats

Conversation

@groeneai

@groeneai groeneai commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125361
Related: #121821
Related: #125095
Related: #109838

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 an INSERT into an ORC or Avro Iceberg table terminating the server, or committing a data file with wrong or missing field ids so that later queries returned wrong results, when a column the INSERT writes was dropped or renamed away while it was running. Such an INSERT is now rejected with INCORRECT_DATA, as it already was for Parquet.

Description

On 26.9.19.9, an INSERT into an ORC or Avro Iceberg table whose structure predates an ALTER TABLE ... DROP COLUMN (a concurrent ALTER, or a table attached with iceberg_metadata_file_path to the older metadata) aborts the process in DataFileStatistics::getNullCounts. After DROP COLUMN + ADD COLUMN it commits statistics under shifted field ids, so WHERE d IS NULL returns 3 of 6 rows; after RENAME COLUMN it writes the column without a field id. Parquet already refuses. The script in #125361 is the failing input.

Root cause. Only the Parquet writer checked that every written column has a field id in the schema being written. For ORC/Avro the writer found no id, and DataFileStatistics fell back to schema-positional ids: past the end for a wider block, shifted after DROP + ADD.

Change. validateIcebergFieldIds moves from the Parquet writer to Formats/FormatFilterInfo, and the Iceberg writer calls it for every format before the first data file is created. DataFileStatistics takes the written columns' ids only, with no fallback. Parquet behaviour is unchanged; mutations are Parquet-only; experimental compaction is unchanged. #109838 adds an independent, earlier check. #125095 (closed) had the same change. A rename that keeps every written name present (two columns swapping names) still binds by name, as on master for every format.

Validation. test_storage_iceberg_no_spark/test_writes_stale_insert_after_alter.py covers DROP COLUMN, DROP + ADD, RENAME and a nested-field rename, each for Parquet, ORC and Avro. It asserts INCORRECT_DATA, that a refused INSERT leaves the table's files unchanged, and that a pinned INSERT after ADD COLUMN is still accepted (Parquet, ORC). On master (1d607cb1acf3) 8 of its 14 cases fail: the ORC/Avro DROP COLUMN cases abort the server and the other ORC/Avro cases are accepted; the Parquet cases pass. Here all 14 pass.


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

Version info

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

groeneai and others added 2 commits October 19, 2026 18:03
…, for every format

An INSERT into an ORC or Avro Iceberg table whose block structure predates
an ALTER TABLE ... DROP COLUMN (a concurrent ALTER, or a table attached with
iceberg_metadata_file_path to the older metadata) aborted the process with a
libc++ hardening out-of-bounds assertion in DataFileStatistics::getNullCounts.
At equal width (DROP + ADD, RENAME) it committed a data file whose statistics
carried the wrong field ids, so manifest pruning returned wrong results.

The writer takes its field ids from the latest schema, while the block comes
from the older one. Only the Parquet writer refused a column without a field
id (validateIcebergFieldIds in convertSchema). For ORC and Avro
fieldIdsOfWrittenColumns returned {} and the DataFileStatistics constructor
fell back to schema-positional ids: past the end for a wider block, naming the
wrong columns at equal width.

Move validateIcebergFieldIds unchanged from the Parquet writer to
Formats/FormatFilterInfo (the Parquet directory is built only with USE_PARQUET,
the Iceberg writer with USE_AVRO) and call it in fieldIdsOfWrittenColumns for
every written column, so the first MultipleFileWriter constructor throws
INCORRECT_DATA before any data file exists. DataFileStatistics now takes only
the written columns' ids; the positional fallback and the unused
MultipleFileWriter::schema member are gone. Parquet keeps the same check and
message. Drop the now unused INCORRECT_DATA error code from PrepareForWrite.cpp.

Closes ClickHouse#125361

Co-Authored-By: Claude Opus 5.5 <[email protected]>
validateIcebergFieldIds: state the Nullable/LowCardinality naming rule in one line without citing Parquet-local helpers; drop the recursion narration.

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; 3 findings in the full pass, 0 in the delta recheck after one fix round) plus my own review.

# Sev Finding Verdict Evidence / action
1 ❌ A rename permutation (a -> tmp, b -> a, tmp -> b) keeps every name, so a stale INSERT is accepted and binds by name DISAGREE Unchanged by this PR in all three formats (master accepts it the same way; this PR only changes inputs with a missing name or path). Binding by planning-time field id would need the planning schema in the sink. Title and changelog narrowed to what is guaranteed.
2 ⚠️ The test accepted any error and checked only committed rows AGREE, fixed before publication Asserts INCORRECT_DATA, unchanged table files after a refusal, and a pinned INSERT after ADD COLUMN that is still accepted
3 💡 Use Critical Bug Fix DISAGREE That category is used on a maintainer's request only

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

Session id: cron:clickhouse-review-slot-8:20261019-180600

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The #125361 script (one ALTER per clickhouse-local call, pin checked with DESCRIBE) fails on every run: master drop ORC/Avro abort in getNullCounts, drop_add 0; official 26.9.19.9 aborts with rc 134 and gives drop_add 0.
b Root cause explained? The writer's field ids come from the latest schema, the block from the older one. For ORC/Avro the id lookup returned {} and DataFileStatistics fell back to schema-positional ids: out of bounds for a wider block, shifted ids after DROP + ADD. Only Parquet checked field ids.
c Fix matches root cause? Yes. The writer refuses a written column (at any depth) without a field id, for every format, with the existing Parquet check; statistics take the written ids with no fallback. No bounds guard.
d Test intent preserved / new tests added? New 05407_iceberg_insert_column_dropped_or_renamed_after_planning: 8 stale cases asserting INCORRECT_DATA and an unchanged file inventory, a pinned INSERT after ADD COLUMN that must be accepted, and a current-structure control; no existing test changed.
e Both directions demonstrated? Yes. Master: drop ORC/Avro terminated, the 5 equal-width cases ok with 6 rows, drop_add 0, and every refusal or abort changes the table's files (Parquet included); this PR: every stale case INCORRECT_DATA with files unchanged, both controls OK. 50/50 randomized runs pass (max 16.0 s).
f Fix is general across code paths? Both statistics constructions (writer start and every rollover) use the checked ids; the Parquet format path calls the same function; mutations are Parquet-only; experimental compaction is unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? Nullable/LowCardinality are stripped and Tuple/Array/Map are recursed (existing logic); covered: three formats, DROP, DROP + ADD, RENAME, nested Tuple rename. A narrower block (ADD COLUMN, #121821) is still accepted, asserted in the test.
h Backward compatible? (maintainer-approved exception only) No setting or format change. A stale ORC/Avro INSERT that aborted or wrote wrong statistics now fails with a retryable INCORRECT_DATA, as Parquet already does.
i Invariants and contracts preserved? Every written column has an id in the schema being written, and statistics are keyed by those ids in block order. The check throws before the first data file exists, so a refused INSERT leaves the table's files unchanged (asserted for every stale case).

Session id: cron:clickhouse-impl-slot-40:20261019-175500

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @SmitaRKulkarni, could you review this and add the can be tested label so CI runs? The Iceberg writer now checks for ORC and Avro, as it already did for Parquet, that every written column has a field id in the schema being written, so a stale INSERT after DROP COLUMN is refused with INCORRECT_DATA instead of aborting in DataFileStatistics::getNullCounts or committing statistics under shifted field ids.

@clickhouse-gh

clickhouse-gh Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7f6861e]

Summary: ✅


AI Review

Summary

The PR rejects stale Iceberg inserts with missing field IDs before creating a data file for Parquet, ORC, and Avro, and removes the positional statistics fallback. The focused regression tests cover dropped and renamed fields and preserve supported inserts after ADD COLUMN. No actionable findings in head 7f6861e5b61819b6792038295e04e8bbca453382.

Missing context / blind spots
  • ⚠️ No tests were run locally. Current-head integration results are pending; runtime evidence is the author's documented 14-case before/after validation. The integration jobs must confirm the current revision.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Oct 19, 2026
@scanhex12 scanhex12 self-assigned this Oct 19, 2026
Requested in review (ClickHouse#126768): the stateless 05407 test was hard to read.
The same cases now live in test_storage_iceberg_no_spark as one pytest per
schema change (DROP COLUMN, DROP + ADD COLUMN, RENAME COLUMN, nested field
rename, each for Parquet, ORC and Avro, plus the ADD COLUMN positive
control), using the iceberg_utils helpers and the same pinned-metadata
technique as test_remove_orphan_files_ignores_pinned_metadata.

The ADD COLUMN control excludes Avro: there the stale INSERT is accepted
(also on master) but every later SELECT fails with "Field d not found in
Avro schema", which this change does not touch.

Measured: fix binary 42/42 (14 cases x 3). Master 94e0f5a: 13 of 14
cases fail (ORC/Avro DROP COLUMN abort the server, ORC/Avro DROP + ADD,
RENAME and nested rename are accepted, every Parquet refusal leaves a data
file), the two ADD COLUMN controls pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 21, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 21, 2026
The RENAME COLUMN block relied on a stale INSERT that writes the renamed column
without a field id. ClickHouse#126768 refuses that INSERT for every format, so the block
would start failing as soon as it is merged.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 838446a

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, distributed plan, s3 storage, parallel) / 04950_distributed_plan_runtime_filter_delivery_from_join_stage flaky, not from this PR (it changes only Iceberg INSERT validation): the tdigest estimate signature, 8 of 69 reruns failed. This run re-built the merge commit pinned on 2026-10-19, before the fix merged, and the fix is absent from the tested tree #126385 (ours, merged)
Mergeable Check, PR praktika rollups of the row above #126385 (ours, merged)

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

Session id: cron:our-pr-ci-monitor:20261021-090014

…dropped-renamed-column-all-formats

# Conflicts:
#	src/Processors/Formats/Impl/Parquet/PrepareForWrite.cpp
@clickhouse-gh

clickhouse-gh Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 7f6861e5b with master 28cd3f355 (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

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

Job report

@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, thanks!

@alexey-milovidov alexey-milovidov self-assigned this Nov 13, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit ee1e073 Nov 13, 2026
187 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 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-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... 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.

Stale ORC/Avro Iceberg INSERT after DROP COLUMN aborts in getNullCounts

4 participants