Skip to content

Fix Iceberg schema evolution of decimals widened inside arrays, maps and structs - #130114

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-nested-decimal-evolution
Nov 8, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/iceberg-nested-decimal-evolution

Conversation

@groeneai

@groeneai groeneai commented Nov 8, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #130024
Related: #130016

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 Iceberg tables in which a decimal inside an array, a map or a struct was widened to a precision with a wider storage type (for example decimal(12, 4) to decimal(20, 4)): every query to such a table failed with Bad get: has Decimal64, requested Decimal128.

Description

On 26.10.2.103 and 26.3.60.2, SELECT * FROM icebergLocal(...) on the Apache Doris complex_*_schema_change tables from #130016 fails with BAD_GET in EvolutionFunctionStruct: col3 is list<decimal(12, 4)> in the data files and list<decimal(20, 4)> in the current schema, a legal Iceberg promotion.

For a complex column, IcebergSchemaProcessor::getSchemaTransformationDag adds one EvolutionFunctionStruct whose result type is the new type. It renames, reorders, adds and drops nested fields on Fields and inserts them into a column of that type without converting the primitive leaves, so a Decimal64 field lands in a Decimal128 column. Top-level columns get a CAST in the DAG for the same promotions; nested ones got none.

Now the evolution function returns the new structure in which every nested primitive changed by a legal promotion (allowPrimitiveTypeConversion, as for top-level columns) keeps its old type (struct fields matched by id, list element, map key and value), and the DAG casts the result to the new type. When nothing nested was promoted, the DAG is unchanged.

Validation: the new integration test test_decimal_evolved_nested (Decimal32 to Decimal64 and Decimal64 to Decimal128 in an array, a map value, a struct field and an array of structs, together with a rename, a reorder and an added field) fails on master and passes with the fix. The gtest IcebergSchemaProcessor.WidenMapKeyDecimalAcrossSchemaIds covers a widened map key, which Iceberg writers do not produce. The four Doris tables return their 15 rows, and the schema-change part of #130016's 05721_iceberg_doris_schema_evolution matches its reference except rename_col7.add, a struct subcolumn read that fails without any promotion too (#125252). The test_storage_iceberg_schema_evolution package passes.


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

Version info

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

groeneai and others added 3 commits November 8, 2026 08:14
…and structs

For a complex column, getSchemaTransformationDag built one EvolutionFunctionStruct
whose result type was the new type. Its executable moves Fields between nested
positions (id-based rename, reorder, add, drop) and inserts them into a column of
that type, but never converts primitive leaves, so a decimal widened across a
storage width (decimal(12, 4) -> decimal(20, 4), Decimal64 -> Decimal128) failed
with "Bad get: has Decimal64, requested Decimal128" and the table was unreadable.
int -> long and float -> double only worked because a Field stores them as Int64
and Float64. Top-level columns get a CAST in the DAG for the same promotions.

The evolution function now returns the new structure in which every nested
primitive changed by a legal promotion (allowPrimitiveTypeConversion, the
predicate of the top-level branch) keeps its old type: struct fields matched by
id, list element, map key and value. The DAG then casts that to the new type.
A named-tuple CAST matches elements by name, and the names are the new ones on
both sides, so it only changes leaf types. When nothing nested was promoted the
DAG is unchanged.

Closes ClickHouse#130024

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Iceberg writers refuse map key updates, so the integration test can only widen
a map value. Build the case from JSON schemas instead: a decimal(9, 2) map key
widened to decimal(18, 2) is read through the transformation DAG as
Map(Decimal(18, 2), Nullable(Int32)) with the value preserved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the getSchemaTransformationDag comment on the post-evolution cast to one line.

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

groeneai commented Nov 8, 2026

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 over 2 rounds; round 2 on the fix commit found nothing).

# Sev Finding Verdict Evidence / action
1 ⚠️ No test reddens if the map-key substitution (SchemaProcessor.cpp:827) is removed: the integration test widens only b.value AGREE, fixed @ da5f577 Iceberg writers refuse map key updates, so the case is a gtest built from JSON schemas (IcebergSchemaProcessor.WidenMapKeyDecimalAcrossSchemaIds); it fails with Bad get: has Decimal32, requested Decimal64 without the substitution and passes with it
2 💡 The integration test writes Parquet only DISAGREE The transformation DAG runs after the format reader, independent of the format; the Doris ORC v1/v2 tables return their 15 rows with the fix and fail with BAD_GET on master

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-11:20261108-092500

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM icebergLocal('warehouse/wh/test_db/complex_parquet_v2_schema_change') ORDER BY id on the Doris tables of #130016 fails with BAD_GET every time on master, 26.10.2.103 and 26.3.60.2 (also the ORC and v1 copies); the new integration test fails every time on master.
b Root cause explained? Yes. The complex-type branch of getSchemaTransformationDag gives EvolutionFunctionStruct the NEW type; its executable moves Fields between nested positions and inserts them into a column of that type without converting primitive leaves, so a Decimal64 field is inserted into ColumnDecimal<Decimal128>. Top-level promotions get a DAG CAST; nested ones had none.
c Fix matches root cause? Yes. The function's result type now keeps the old type for nested leaves changed by a legal promotion, matching the Fields it inserts, and the DAG casts the column to the new type, as for top-level columns.
d Test intent preserved / new tests added? New integration test test_storage_iceberg_schema_evolution/test_decimal_evolved_nested.py, plus the gtest IcebergSchemaProcessor.WidenMapKeyDecimalAcrossSchemaIds for a widened map key; no existing test changed.
e Both directions demonstrated? Yes. The new test and the Doris query fail on the master snapshot and on the same tree without the fix, and pass with it. Disabling the struct branch or the map-value substitution makes the test fail on c and b; the map-key gtest fails with Bad get: has Decimal32, requested Decimal64 when the map-key substitution is disabled and on the same tree without the fix.
f Fix is general across code paths? Yes. One recursive function covers list element, map key and value, struct fields (by id) and their nesting; EvolutionFunctionStruct has a single construction site; time travel uses the same DAG.
g Fix generalizes across inputs (params/datatypes/wrappers)? Decimal32 to Decimal64 and Decimal64 to Decimal128 in arrays, map values, struct fields and arrays of structs, with rename, reorder, an added field and rows beyond the old precision; Parquet and ORC; nested int to long and float to double still pass (existing package tests and the Doris tables).
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; DAGs without a nested promotion are unchanged; previously failing tables become readable.
i Invariants and contracts preserved? Yes. The DAG output type equals the read schema type on every path (names, order and nullability come from the new schema, a cast is added whenever a leaf differs); the helper does not modify the schema JSON it reads.

Session id: cron:clickhouse-impl-slot-4:20261108-065900

@groeneai

groeneai commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator Author

cc @scanhex12 @arsenmuk, could you review this and add the can be tested label so CI runs? For a complex Iceberg column, EvolutionFunctionStruct inserted old-typed nested Fields into a column of the new type, so a decimal widened inside an array, map or struct failed with BAD_GET; the evolution function now keeps the old type for legally promoted nested primitives and the DAG casts the result to the new type, as for top-level columns.

@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d96dc8f]

Summary: ✅

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) SKIPPED GitHub API error in test selection, rerun to test

AI Review

Summary

The PR fixes Iceberg decimal widening inside nested containers by preserving the original primitive types during structural evolution, then applying CAST. Reviewed all four changed files and the prior discussion at d96dc8fb7fdad82613d6c8e4cc422154ddde1a29; no actionable findings.

Consumer trace: EvolutionFunctionStruct feeds the subsequent DAG CAST when a primitive representation changes. The recursive Array, Tuple, and Map cast implementations convert those leaves; IcebergMetadata::getSchemaTransformer and StorageObjectStorageSource consume the complete DAG through ExpressionActions, after that conversion.

Missing context / blind spots
  • ⚠️ No local ClickHouse build was available, so the added integration test and gtest were not executed during this review. The author reports that both reproduce the exception without the fix and pass with it. The current CI run still has integration and bugfix validation pending; their completed results would independently confirm the reported validation.
Final Verdict

Status: ✅ Approve. No code changes requested; CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default can be tested Allows running workflows for external contributors comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d96dc8fb7 with master 7b5f2bf32 (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.

Object file sizes

4 object files changed (+63.52 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/SchemaProcessor.cpp.o 554.38 KiB 617.91 KiB +63.53 KiB (+11.46%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

51 translation units recompiled, 542 s compile time in total, 51 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.

Good.

@alexey-milovidov alexey-milovidov self-assigned this Nov 8, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 8, 2026
Merged via the queue into ClickHouse:master with commit 2ba2cfd Nov 8, 2026
374 of 376 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 Nov 8, 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.

Iceberg: decimal widening inside a list makes the table unreadable (Bad get: has Decimal64, requested Decimal128)

3 participants