Skip to content

Keep carried-over Iceberg manifest-list counts in the new list's shape after a format-version upgrade - #130800

Merged
alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-v1-upgrade-manifest-list-counts-123045
Nov 12, 2026
Merged

alexey-milovidov merged 2 commits into
ClickHouse:masterfrom
groeneai:fix-iceberg-v1-upgrade-manifest-list-counts-123045

Conversation

@groeneai

@groeneai groeneai commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123045

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 Iceberg table becoming unreadable (INCORRECT_DATA) when another engine had upgraded it from format version 1 to 2 or 3 and ClickHouse then made the next commit (INSERT, ALTER TABLE ... DELETE/UPDATE, ALTER TABLE ... DROP PARTITION). Also fixed any ClickHouse commit writing 0 as the file counts of manifests listed by Iceberg Java before 1.5, which made Java-based readers skip those manifests. Closes #123045.

Description

On 26.10.2.103, after another engine upgrades an Iceberg table from format version 1 to 2, the first ClickHouse INSERT makes every later read of the table fail with Cannot read Iceberg avro manifest file ...: Invalid value for bool. (INCORRECT_DATA).

generateManifestList copies the parent snapshot's manifest-list entries into the new list. In a v1 list the six *_files_count / *_rows_count fields are ["null", int/long] unions, in v2/v3 they are plain, and the copy assigned the source datum verbatim. avro-cpp encodes a union index for any datum that is itself a union, so the rest of the file was misaligned. The same copy looked the file counts up only by their current names, while Iceberg Java before 1.5 names them added_data_files_count etc. (same field ids), so any ClickHouse commit to a table whose current list Java wrote, upgraded or not, wrote them as 0, and Java scans skip a manifest with no added or existing files.

Each count is now rebuilt with setVersionedField in the target field's shape, with a fallback to the old names, and a count of the wrong Avro type fails with ICEBERG_SPECIFICATION_VIOLATION. A missing or null count cannot go into a v2/v3 list, so that case now fails with NOT_IMPLEMENTED before anything is committed; none of the 135 manifest lists under tests/ has one, and no ClickHouse writer produces one, so it has no test. Lists that were already written correctly do not change.

The new test (v1 -> v2 and v1 -> v3 INSERTs, and a copy of the Iceberg 1.4.3 fixture ice143_v2_position_deletes) fails on master and passes with the fix. Locally, ALTER TABLE ... DELETE, UPDATE and DROP PARTITION after the upgrade are red on master and green with the fix.


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

Version info

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

groeneai and others added 2 commits November 11, 2026 13:02
After another engine upgrades an Iceberg table from format version 1, the
first ClickHouse commit (INSERT, ALTER DELETE/UPDATE, DROP PARTITION) copies
the parent's v1 manifest-list entries into a v2 or v3 list. The six counts
are ["null", int/long] unions in v1 and plain values in v2/v3, and the copy
assigned the source GenericDatum verbatim. avro-cpp's GenericWriter encodes a
union index for any datum that is itself a union, whatever the writer schema
says, so every count got an extra varint and the rest of the file was
misaligned: every later read of the table failed with INCORRECT_DATA.

The three file counts were also looked up only by their current names.
Iceberg Java before 1.5 calls them added_data_files_count and so on (same
field ids, Java resolves by id), so for such a parent list the new entries
got 0 file counts, and Java scans skip a manifest whose added and existing
file counts are 0.

Each count is now rebuilt from its value with setVersionedField, which writes
the target field's shape, and the file counts fall back to the old names. A
missing or null count cannot be written into a v2/v3 list (the spec requires
it there, and recomputing it from the manifest is not implemented), so that
case now throws NOT_IMPLEMENTED before anything is committed instead of
writing a corrupt or zero count; a v1 target keeps it null as before.

Closes ClickHouse#123045

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the copy_count comment from 3 lines to 2.

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

clickhouse-gh Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [906b374]

Summary: ✅


AI Review

Summary

Reviewed #130800 at 906b374299f4150a414fcb170d438359e95b14d1, including all prior discussion, the complete diff, surrounding implementation, and callers. The change rebuilds carried-over Iceberg manifest counts in the destination schema and preserves file counts written under legacy Java field names. No actionable findings remain. No inline comments were posted.

Missing context / blind spots
  • ⚠️ Independent runtime verification was unavailable: this checkout has no ClickHouse binary or build directory. The fast-test report skips 05620_iceberg_v1_upgrade_manifest_list_counts, and the fetched workflow reports functional bugfix-validation jobs as dropped. Regression evidence consists of the added focused test and the author's reported master-fails/fix-passes runs. A full-build stateless run would close this independent verification gap.
Final Verdict

✅ Approve — no unresolved code findings or required revisions.

@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; 1 finding) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test does not discriminate every copy_count call, the non-INSERT callers, or the missing/null guards DISAGREE Reverting either half of the fix fails it (cases 1-2 INCORRECT_DATA, case 3 5 0); the callers share one per-entry body (ALTER DELETE/UPDATE/DROP PARTITION checked locally); no fixture or ClickHouse writer produces old-name nonzero existing/deleted counts or a list without counts.
2 💡 NOT_IMPLEMENTED where a v2 source missing a count is a spec violation noted fail-closed either way; no input produces it
3 💡 Test size noted same shape as 05394_iceberg_v3_upgrade_insert_assigns_row_ids

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

Session id: cron:clickhouse-review-slot-10:20261111-130700

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 11, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. 05620_iceberg_v1_upgrade_manifest_list_counts fails every run on master (INCORRECT_DATA: Invalid value for bool on every read after the upgrade; the Iceberg 1.4.3 case prints 5 0). The issue's reproducer and a released 26.10.2.103 clickhouse local fail the same way.
b Root cause explained? generateManifestList assigned the parent v1 entry's ["null", int/long] count datums verbatim into the plain v2/v3 slots; avro-cpp's GenericWriter writes a union index for any union datum, which misaligns the rest of the file. The file counts were also looked up only by their current names, missing Iceberg Java < 1.5's added_data_files_count etc.
c Fix matches root cause? Yes: each count is rebuilt in the target field's shape with the existing setVersionedField, at the copy, with a fallback to the old names.
d Test intent preserved / new tests added? New stateless test: v1 -> v2 (two INSERTs, partitioned), v1 -> v3 (_row_id), and the Iceberg 1.4.3 fixture; it checks the reads and the counts decoded from the new manifest list.
e Both directions demonstrated? Master build: FAIL on all three cases. Fix build: OK, and 50/50 randomized runs OK.
f Fix is general across code paths? The one copy serves INSERT (including the commit-conflict retry), ALTER TABLE ... DELETE/UPDATE, DROP PARTITION and compaction carry-forward; DELETE, UPDATE and DROP PARTITION after the upgrade were checked locally (red on master, green with the fix).
g Fix generalizes across inputs (params/datatypes/wrappers)? v1 -> v2 and v1 -> v3, partitioned and not, current and legacy names; a null or missing count fails with NOT_IMPLEMENTED into v2/v3 and stays null in v1. No such list among the 135 under tests/.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or format change; v1 -> v1 and v2 -> v2 lists decode to the same counts as before.
i Invariants and contracts preserved? Every carried-over entry is encoded in the new list's schema with the parent's counts; the new error is raised while the list is built, before any commit; the v3 row-id assignment still runs after the copy.

Session id: cron:clickhouse-impl-slot-6:20261111-124501

@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 906b37429 with master 2202f3903 (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.66, programs/clickhouse-keeper ×0.69 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.8 s 11.2 s +7.4 s (+192%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.4 s 8.2 s +6.0 s (+270%)
Compile time of recompiled translation units

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Nov 12, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 12, 2026
Merged via the queue into ClickHouse:master with commit 1937515 Nov 12, 2026
597 of 601 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 12, 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
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…t-list-bucket-partition-summary

Conflict in IcebergWrites.cpp, two hunks:
- The summary write loop: master (ClickHouse#129812) only reworded the comment on
  its `bounds_unavailable` check. Kept this branch's form, which has no
  check: `canWritePartitionSummary` already returns early for a manifest
  with such a field.
- The manifest-list carry-forward: master (ClickHouse#130800) rebuilds each count
  in the new list's shape with `copy_count`. Took master's counts and
  kept this branch's guarded copy of `partitions`.

Conflict in ChunkPartitioner.h: master added `[[nodiscard]]` to
`getResultTypes`; kept it together with this branch's comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

Iceberg v1→v2 upgrade: INSERT corrupts v2 manifest list with v1 union counts

3 participants