Skip to content

Support decimal types for writing in data lakes - #115832

Merged
scanhex12 merged 9 commits into
masterfrom
iceberg-decimal-support
Aug 28, 2026
Merged

scanhex12 merged 9 commits into
masterfrom
iceberg-decimal-support

Conversation

@scanhex12

@scanhex12 scanhex12 commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Decimal columns could not be written to Iceberg tables at all: getIcebergType and getAvroType had no case for them, so CREATE TABLE with a decimal column failed with Unsupported type for iceberg.

This adds the write side for Decimal32, Decimal64, Decimal128 and Decimal256:

  • the table schema records the column as Iceberg decimal(P, S);
  • the manifest partition schema declares it as an Avro fixed of the minimum width that holds every value of the precision, and partition values are serialized as the unscaled value in two's-complement big-endian form, per Appendix D of the spec;
  • lower_bounds/upper_bounds statistics are written for decimal columns in the same encoding, and decimal partition values are decoded back on the read path so that partition pruning works on them.

Decimal256 is written as decimal(P, S) with a precision above the 38 the Iceberg spec allows. That is deliberate: ClickHouse reads such metadata back with the same type (createDecimal<DataTypeDecimal> accepts precision up to 76), and it is left to users to avoid types that other engines do not support.

Two bugs found by CI on the first revision are fixed in the follow-up commits: every partition field was serialized against the Avro node of the first partition field, and decimal partition values were dispatched on the Field type, which also matched DateTime64 and turned it into a fixed decimal instead of a long.

Review follow-ups: the Avro fixed name of a decimal partition field now includes the partition field id, so two partition columns of the same decimal shape no longer collide in one manifest schema; and the min/max bound deserialization handles Decimal128 and Decimal256, so the statistics written for wide decimals are actually consumable by partition pruning. Both are covered by new integration tests. A further review round found that a manifest rewrite (OPTIMIZE TABLE ... MANIFEST) feeds partition tuples read back from Avro — where a decimal is the raw fixed bytes in a String field — straight back into the manifest writer; both decimal serializers now accept that representation as well, covered by an integration test compacting a decimal-partitioned table.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=latest&name_0=PR

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Support Decimal types when writing into Iceberg tables, including decimal partition columns and decimal min/max statistics.


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

Version info

  • Merged into: 26.9.1.240 (included in 26.9 and later)
  • Backported to: 26.8.1.2023, 26.7.7.46

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [54aef01]

Summary: ✅


AI Review

Summary

This PR adds write-side support for Iceberg Decimal columns, including decimal partition values, manifest bounds, and manifest-rewrite round-trips. Most of the earlier review issues are fixed, but I still see one unresolved read-path correctness gap for identity-partitioned decimals, and I still disagree with the deliberate choice to emit out-of-spec Iceberg metadata for Decimal256.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/ManifestFilesPruning.cpp:206-207] Decimal partition bytes are decoded only in the pruning scratch copy. The stored parsed_entry->partition_key_value remains a raw Avro fixed String, and getIdentityPartitionColumnValues later passes that through convertFieldToTypeOrThrow at src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:1639. The String to Decimal conversion at src/Interpreters/convertFieldToType.cpp:132 parses decimal text, not Iceberg binary. A concrete trace is 1.50: the manifest stores unscaled 150 as 0x00 0x96, the parser stops at the leading NUL, and the reconstructed constant becomes 0.00. StorageObjectStorageSource uses those identity-partition values to materialize projected partition columns and substitute them into PREWHERE / row-level filters, so decimal identity partitions can still produce wrong results. Suggested fix: normalize decimal partition values once when parsing the manifest, or teach getIdentityPartitionColumnValues to decode decimal String fields with the new helper, then add a focused regression that projects and filters on an identity Decimal partition column.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:605-609] [dismissed by author -- https://github.com/Support decimal types for writing in data lakes #115832#discussion_r3832413741] The writer still advertises ClickHouse Decimal256 as Iceberg decimal(P, S) even though the Iceberg spec caps decimal precision at 38. That means a table written with Decimal(39..76, S) now deliberately emits metadata that spec-compliant readers are allowed to reject, so "support Decimal types when writing into Iceberg tables" is only true for ClickHouse-specific consumers. Suggested fix: reject Decimal256 on the Iceberg write path, or gate the nonstandard extension behind an explicit compatibility setting / type contract instead of emitting it as plain Iceberg decimal.
Final Verdict

❌ Request changes.

LLVM Coverage Report

Measured on commit 54aef01.

Metric Baseline Current Δ
Lines 88.40% 88.40% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 80.70% 80.70% +0.00%

Changed lines: Changed C/C++ lines covered: 154/212 (72.64%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 21, 2026
@scanhex12 scanhex12 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 54aef01e2 with master 90144f901 (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
Binary Master PR Δ
programs/clickhouse-stripped 712.33 MiB 709.29 MiB -3.04 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

8 object files changed (+70.11 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o 906.96 KiB 938.88 KiB +31.92 KiB (+3.52%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp.o 959.54 KiB 980.17 KiB +20.63 KiB (+2.15%)

737 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

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Aug 22, 2026
Two defects in the manifest writer, both reported by CI:

1. Every partition field was serialized against `leafAt(0)` of the partition
   record, so only the first partition column got its own Avro node. With a
   multi-column spec, a later `Nullable` column built its `GenericUnion` from
   the first field's schema and a later decimal column used the first field's
   `fixed` size. Restore the lookup of the field index by name.

2. Decimal partition values were dispatched on the `Field` type, but
   `DateTime64` is also kept in a `DecimalField`, so a `DateTime64` partition
   was written as a `fixed` decimal instead of a `long`. That tripped
   `Logical error: 'schema->type() == avro::AVRO_FIXED' (STID: 1288-3bd5)` in
   `04501_iceberg_datetime64_partition_pruning` and failed
   `test_writes_field_partitioning`, which partitions by nine columns
   including a `DateTime64`. Dispatch on the partition column type instead.

The `chassert` on the Avro node kind becomes a regular exception: in a release
build it was a no-op and the writer would have produced a malformed manifest.

Also, `icebergDecimalRequiredBytes` computed the width from a signed `Int256`
whose intermediate `(1 << 255) - 1` overflows, and the new decimal decoder in
`ManifestFilesPruning` silently left the value as a `String` when the byte
count did not fit the type. Both are now computed on the unsigned type and
report a malformed manifest as an error.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=latest&name_0=PR
Related: #115832
alexey-milovidov and others added 4 commits August 25, 2026 11:48
`fixed` is a named Avro type, and the name was derived only from `(precision, scale)`,
so `PARTITION BY (price_a, price_b)` with two `Decimal(18, 4)` columns emitted two
definitions of the same name `decimal_18_4` into one manifest schema and failed
schema compilation on insert. Include the partition field id in the name.

Co-Authored-By: Claude Fable 5 <[email protected]>
The bound deserializer hard-capped decimal bounds at 8 bytes and reconstructed only
`Decimal32` and `Decimal64`, so the `lower_bounds`/`upper_bounds` the writer now
emits for wider decimals could never be turned into a `Range` and
`IcebergMinMaxIndexPrunedFiles` never fired for them. Decode through the native
type of the expected decimal, like the partition value decoding already does.

Co-Authored-By: Claude Fable 5 <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115832&sha=d6fc50fc82e88d04827d523dac76d796acdf892a&name_0=PR&name_1=Stateless%20tests%20%28amd_msan%2C%20WasmEdge%2C%20parallel%2C%202%2F3%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. 02805_distributed_queries_timeouts failed once with Connection to localhost:9000 terminated. (NETWORK_ERROR) while cancelling a remote query; the in-run reruns all passed and the same transient failure shows up on unrelated PRs (#114263, #101783, #110459), so it is unrelated to this PR. (The other red job, 04235_streaming_queries_alter_projection_rejected on the old-analyzer coverage run, is addressed by #115957, which this branch has now merged in.)

@groeneai

Copy link
Copy Markdown
Collaborator

#112229 is the fix in progress, open since 2026-07-28 and awaiting review rather than awaiting work.

It covers the failure in your report, which is the async_socket_for_remote=1 statement (line 5 of the test). Both async checkTimeout() implementations set a member flag as soon as the receive timer appears among the descriptors of one epoll wake, before that flag is combined with socket readiness, and nothing ever clears it. A wake in which the socket and the timer are ready at the same time therefore delivers its packet correctly but leaves the connection latched as timed out. On the async path the latch also makes cancelBefore() skip draining the pending packet, so the connection is torn down unsynchronised, which is where the Connection to localhost:9000 terminated. (NETWORK_ERROR) on cancellation comes from.

One correction on the corroborating pull requests, because it changes what #112229 closes. The three statements of 02805 exercise different carriers, and the timeout message form separates them: (socket ..., receive timeout N ms) is emitted only by the async and hedged carriers (AsyncTaskExecutor.cpp:130, HedgedConnections.cpp:451), while (peer: ..., local: ..., N ms) is emitted only by ReadBufferFromPocoSocket.cpp:89 on the synchronous one. Of the 11 failures of this test in the last 60 days, 9 record the query that failed (the other two failed for unrelated reasons, a quota error on #110202 and a memory limit on #110102), and they split three ways:

So #114263 and #110459, two of the three you cite, are the synchronous statement. That path has no epoll timer, so the latch cannot reach it, and it is also the only one of the three carriers that has failed on master:

I have no fix in progress for that synchronous half and no root cause for it yet. I can investigate it in a separate pull request if you want it tracked.

alexey-milovidov and others added 2 commits August 27, 2026 15:14
Address review: `OPTIMIZE TABLE ... MANIFEST` reads partition tuples back
from the source manifests, where a decimal partition value is parsed from
the Avro `fixed` as its raw bytes (a `String` field), and both rewrite
paths feed that row straight back into `generateManifestFile` (and into
the `entry_partition_summaries` of the manifest list). `makeDecimalFixedDatum`
and `dumpDecimalValue` accepted only a typed `DecimalField` there, so
compaction of any decimal-partitioned table threw on `safeGet`.

Both serializers now also accept the read-back representation: the bytes
already hold the unscaled value in two's-complement big-endian form, so
they are re-padded to the target `fixed` width (partition values) or
re-trimmed to the minimum length (partition summary bounds) instead of
being decoded and re-encoded.

Covered by `test_optimize_manifest_files_decimal_partition`, which fails
with `Bad get: has String, requested Decimal` without the fix.

Co-Authored-By: Claude Fable 5 <[email protected]>
else if (field.getType() == Field::Types::Int64 && WhichDataType(type).isDateTime64()) /// clickhouse used to write timestamp as simple long in avro
field = DecimalField<Decimal64>(field.safeGet<Int64>(), getDecimalScale(*type));
else if (field.getType() == Field::Types::String && WhichDataType(type).isDecimal())
field = decodePartitionDecimalByType(field.safeGet<String>(), *type);

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.

This only normalizes decimal partition values in the index_value scratch copy that partition pruning uses. The underlying parsed_entry->partition_key_value still stays as the raw Avro fixed bytes, and getIdentityPartitionColumnValues later feeds that String through convertFieldToTypeOrThrow (Utils.cpp:1639). Its String -> Decimal path (convertFieldToType.cpp:132-136) parses decimal text, not Iceberg's two's-complement bytes.

A concrete trace is 1.50: the manifest stores the unscaled value 150 as 0x00 0x96, parseFromString stops at the leading NUL, and the reconstructed partition constant becomes 0.00. StorageObjectStorageSource then uses those identity-partition values to materialize projected partition columns and substitute them into PREWHERE / row-level filters, so a decimal identity partition can still return wrong values even though pruning is fixed here.

Please normalize decimal partition fields once on manifest read, or reuse decodePartitionDecimalByType in getIdentityPartitionColumnValues, and add a focused regression that projects and filters on an identity Decimal partition column.

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.

🕵 Checked this against master (this PR is merged now). The 1.50 -> 0.00 trace does not reproduce: for a decimal identity partition column the manifest value reaching getIdentityPartitionColumnValues is already a Decimal field, not the raw fixed bytes.

Verified under a debugger on a table written by ClickHouse and partitioned by Decimal(7, 2): at Utils.cpp:1639 the field is DB::Field::Types::Decimal32, and SELECT returns 1.50 / 2.50 / -3.25 correctly (same for Decimal(38, 10) and Decimal(50, 5), with partition pruning enabled and disabled) — the Avro reader decodes the annotated fixed for us.

That said, the two encodings the pruner does handle (String decimal bytes, and a legacy DateTime64 written as a plain long) would indeed be reconstructed incorrectly on the identity-projection path, so I factored the decoding out into Iceberg::normalizePartitionValue and used it in both places, with an integration test that reads a decimal identity-partitioned table whose data files no longer store the partition columns: #117090

@scanhex12
scanhex12 added this pull request to the merge queue Aug 28, 2026
Merged via the queue into master with commit 75ed45f Aug 28, 2026
179 checks passed
@scanhex12
scanhex12 deleted the iceberg-decimal-support branch August 28, 2026 09:41
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 28, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Aug 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

@scanhex12 the 26.7 backport #116859 does not build. On its current head 4f8e1edeb3:

src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:357:69: error: use of undeclared identifier 'field_id'; did you mean 'f_field_id'?

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116859&sha=4f8e1edeb3434de0fbd4fe8132123903dd6eb5e9&name_0=BackportPR&name_1=Build%20%28amd_asan_ubsan%29

field_id here is not the Constant.h alias. That macro pastes f_##name, so it only ever declares
f_field_id, identically on 26.7 and master. It is a function-local Int32 inside
extendSchemaForPartitions, introduced together with that function's 4th parameter
partition_spec_fields by #111786, which is on master and 26.8 but not on 26.7 or 26.6. 26.7 still
has the 3 parameter form with a hardcoded 1000 + i, so the cherry-picked field_id argument has
nothing in scope.

The second error, no matching function for call to getAvroType, is clang recovering from the first:
it typo-corrects to f_field_id, whose type is const char * const, which then fails against
getAvroType(DataTypePtr, Int32). That 2 argument signature is already present on the backport head,
so it is not a separate gap. #116860 (26.8) merged green with the same diff, which isolates the
variable. I also resolved every identifier the cherry-picked hunks add against 26.7, including the
contrib/avro pointer, which is the same commit on both refs; field_id is the only unresolved one.

Two ways forward. #111786 is mine and carries no backport label, and v26.7-must-backport on it
expands to exactly {26.8, 26.7} with 26.8 already containing it. But the port is not clean: the
source half auto-merges onto 26.7 while its integration test conflicts, because that test file
arrives with my #109994, which is also unbackported. The cheaper alternative is to adapt this
backport in place, hoisting Int32 field_id = static_cast<Int32>(1000 + i); into the loop and
passing that, which leaves 26.7 writing fallback field ids rather than the persisted spec ids.

#116858, the 26.6 cherry-pick, will hit the same error, and on 26.6 #111786's source half conflicts
as well.

I do not apply labels and I do not hand-resolve release-branch ports, so the choice is yours.

alexey-milovidov added a commit that referenced this pull request Aug 30, 2026
The 26.6 branch misses several master-only refactorings around Iceberg
writes, so the mechanical merge needed adaptation:
- `extendSchemaForPartitions` on 26.6 always assigns partition field ids
  as `1000 + i` (no `spec_has_all_ids` logic), so define `field_id`
  locally for the new `getAvroType` signature.
- Add the `DataTypes/DataTypesDecimal.h` include to `Utils.cpp` and
  `ManifestFilesPruning.cpp` (`getDecimalPrecision`, `checkDecimal`).
- Keep 26.6's pruning loop without the master-only `DateTime64` branch,
  but make it index-based to decode decimal partition values by type.
- Drop `test_manifest_compaction.py`: `OPTIMIZE TABLE ... MANIFEST` does
  not exist on 26.6, so the compaction test cannot run there.

Original PR: #115832
robot-clickhouse-ci-2 added a commit that referenced this pull request Aug 30, 2026
Cherry pick #115832 to 26.6: Support decimal types for writing in data lakes
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 30, 2026
@fm4v fm4v removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 31, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 31, 2026
@fm4v fm4v removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR labels Aug 31, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 31, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 31, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@scanhex12 from my research, ClickHouse Bool should map boolean in iceberg and FixedString(N) should map fixed[N] in iceberg. Are you aware of this? They are not supported I think

clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #115832 to 26.7: Support decimal types for writing in data lakes
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Sep 8, 2026
The backport of ClickHouse#115832 re-imported the upstream
type mapping in `getIcebergType` and, in doing so, replaced the guarded
branch with the unguarded upstream one. A `Decimal` wider than the
Iceberg spec limit was then silently serialized into metadata that other
engines reject, instead of being refused. The guard was added to this
branch in 998bb35.

The Iceberg spec caps `decimal(P, S)` at precision 38, while ClickHouse
`Decimal256` goes up to 76.

Fixes `IcebergTypeMapping.DecimalPrecisionAboveSpecLimitIsRejected` and
`IcebergTypeMapping.NullableDecimalPrecisionAboveSpecLimitIsRejected`,
and the two `rejected: Decimal(39, 2)` scenarios under
`export partition id` and `export part` in the Iceberg regression suite.

CI report: https://altinity-build-artifacts.s3.amazonaws.com/json.html?PR=2320&sha=9091be4a6720c4cc319b24caf95601c7ed0371c2&name_0=PR&name_1=Unit%20tests%20%28asan_ubsan%29
Related: #2320
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Sep 9, 2026
Antalya 26.6 Backport of ClickHouse#115832: Support decimal types for writing in data lakes
@blau-ai blau-ai mentioned this pull request Sep 9, 2026
15 of 30 tasks
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
filimonov pushed a commit to filimonov/ClickHouse that referenced this pull request Sep 14, 2026
…support

Support decimal types for writing in data lakes
filimonov pushed a commit to filimonov/ClickHouse that referenced this pull request Sep 14, 2026
The test came from the backport of ClickHouse#115832 and creates a
`Decimal(76, 20)` column, which this branch refuses -- the Iceberg spec caps
`decimal` at precision 38. It fails on its first CREATE TABLE in every build.

`Decimal256` is unreachable on the write path here, so the column goes. The
refusal itself stays covered by the type-mapping gtest and by the
`rejected: Decimal(39, 2)` scenarios in the regression suite.

Related: ClickHouse#2320

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
pull Bot pushed a commit to erickirt/ClickHouse that referenced this pull request Sep 28, 2026
Iceberg stores a decimal min/max bound rounded to the integral part, so the reader moves each
bound one integral unit outwards before pruning on it. At scale 38 that unit is `10^38` and the
bound lives in an `Int128`, which holds `1.7 * 10^38`, so the shift leaves the type for every
bound of magnitude above roughly 0.70141. `Decimal(38, 38)` is the only width where that happens
to a bound the column can hold: at the other three the largest value the precision allows plus
`10^scale` still fits.

Until ClickHouse#116604 the shift wrapped, which inverted the pair reaching
`KeyCondition::mayBeTrueInRange`, pruned the data file holding the matching rows and lost them
silently. That pull request rejects such a bound instead, which is correct but gives the column
no min/max condition at all - and for a `Decimal(38, 38)` column that is every bound of
magnitude above 0.7, so those tables lost min/max pruning altogether.

A bound only has to stay on the outer side of every value in the file, and the largest magnitude
the precision of the type allows is outside all of them, so it stands in for a widened bound that
no longer fits. A bound that is itself outside that magnitude is one the column cannot hold:
nothing vouches for the values in the file, so there is no stand-in for it and it stays unusable,
which is the case `test_iceberg_inverted_decimal_manifest_bounds` pins for a `Decimal32` bound.

The new test reads a `Decimal(38, 38)` column whose two data files hold `0.99` and `-0.99`: every
filter on the column returns its rows, and a probe outside one of the two shifted bounds prunes
that file and only it. A second table holds `0.1` and `-0.1`, where the shift stays inside
`Int128` whatever the reader does with an overflow, so the two arms together say the pruning is
lost to the overflow rather than to the shape of the test.

Closes: ClickHouse#116999
Related: ClickHouse#116604
Related: ClickHouse#115832

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-ClickHouse__ClickHouse that referenced this pull request Nov 9, 2026
An Iceberg schema was converted to ClickHouse types without checking the
schema-level rules, so metadata that the Java implementation rejects was
read (apache/iceberg-verification cases, issue ClickHouse#130002):

- `identifier-field-ids` naming a field that does not exist, is optional,
  is `float`/`double`, is not primitive, or is nested in a list, a map or
  an optional struct (Java `Schema.validateIdentifierField`);
- a list without `element-id`, a map without `key-id` or `value-id`
  (Java `SchemaParser.listFromJson`/`mapFromJson`);
- a geo type with an empty CRS or an unknown edge interpolation algorithm:
  `getSimpleType` mapped every string starting with `geometry`/`geography`
  to `Geometry` (Java `Types.fromTypeName`, `EdgeAlgorithm.fromName`);
- a table schema that is not `"type": "struct"`.

`IcebergSchemaProcessor::findSchemaViolation` returns the first violation;
`checkSchema` throws ICEBERG_SPECIFICATION_VIOLATION naming the field.

Where it runs:
- every metadata.json copy registered by `addIcebergTableSchema`, before the
  identical-copy fast paths: they compare only `fields`, and with the geo
  parser every geo type compares as `binary`, so an invalid copy of an
  already registered schema-id would return early unchecked;
- manifest header copies get the structural rules only, at registration of a
  new copy: AWS S3 Tables writes header copies with only the partition source
  columns, whose copied `identifier-field-ids` may name absent fields, and
  Java takes the schema from metadata.json (`ManifestReader`);
- `parseTableSchema` checks every entry of `schemas`: a table without a
  current snapshot registers only the current one, while Java parses all
  of them (`TableMetadataParser`).

Writers: `ALTER` deep-copies `identifier-field-ids`, so dropping an
identifier column (or the struct containing one) or making it Nullable
wrote a schema that ClickHouse and Java then refuse to read; it is now
refused with BAD_ARGUMENTS, like Java's `SchemaUpdate`. The REST catalog
server's create-table validates the client's identifier fields the same way.

`decimal(P, S)` with `P > 38` is not rejected: ClickHouse writes it on
purpose (ClickHouse#115832); asked on the issue.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 14, 2026
…anifest lists, keep wide decimals

- `05616` and `05617`: change into the generated table directory and pass relative table names,
  because `icebergLocal` in `clickhouse local` refuses paths outside the working directory
  (the tests failed with `PATH_ACCESS_DENIED` with `clickhouse-test --tmp` outside the checkout).
- `05617`: remap the manifest lists `s3://a/b/*.avro` of `TableMetadataV2Valid` and
  `TableMetadata*StatisticsFiles` into `metadata/` of the table and supply empty manifest lists,
  because describing a table reads the manifest list of the current snapshot.
- `05616`: expect `Nullable(Decimal(39, 0))` for `decimal-precision-over-38`, because ClickHouse
  deliberately supports wide decimals in Iceberg (#115832).

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

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

9 participants