Skip to content

[Iceberg spec fix part 2]: Do not store ClickHouse unsigned integers in narrower Iceberg types - #118596

Merged
scanhex12 merged 9 commits into
masterfrom
iceberg_unsigned_integer_types
Oct 12, 2026
Merged

scanhex12 merged 9 commits into
masterfrom
iceberg_unsigned_integer_types

Conversation

@scanhex12

@scanhex12 scanhex12 commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Iceberg doesn't have integer unsigned type, UInt32 should be converted as Int64

int — 32-bit signed integers — Can promote to long
long — 64-bit signed integers

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):

Do not store ClickHouse unsigned integers in narrower Iceberg types


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

Version info

  • Merged into: 26.10.1.2183-master (included in 26.10 and later)

@mintlify

mintlify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
ClickHouse-docs 🟢 Ready View Preview Oct 11, 2026, 2:15 PM

@scanhex12 scanhex12 self-assigned this Sep 7, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bba9044]


AI Review

Summary

This PR fixes the forward path for new Iceberg tables by widening UInt32 to Iceberg long and rejecting new UInt64 schemas, but it still leaves two upgrade paths unsafe: existing tables created by older releases can still accept INSERT with UInt64, and legacy tables whose Iceberg schema is still int can still accept UInt32 writes. The same stale-type split is also reused by the other Iceberg rewrite paths (ALTER UPDATE/DELETE, compaction, manifest rewrites), so the bug-fix contract is still not upheld after upgrade.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp:1000, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergMetadata.cpp:1704, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1122, src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp:778] UInt64 is only rejected on new CREATE, not on rewrites through existing tables. createInitial now blocks fresh DDL, but the runtime write paths still rebuild their work from the table's existing sample_block: IcebergMetadata::write constructs IcebergStorageSink directly from it, and the mutation/compaction paths do the same when they reopen the table metadata for rewrites. The write-side Avro/schema helpers still accept UInt64 as Iceberg long, so an upgraded server can keep emitting the exact overflow/misencoding path this PR is supposed to close. Suggested fix: move the compatibility check into a shared helper that runs before every Iceberg write/rewrite path, and reject any table whose current ClickHouse schema still contains UInt64.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:341, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:672, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1206, src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:1254, src/Storages/ObjectStorage/DataLakes/Iceberg/ChunkPartitioner.cpp:64, src/Processors/Formats/Impl/Parquet/PrepareForWrite.cpp:351, src/Processors/Formats/Impl/ParquetBlockOutputFormat.cpp:321] The legacy UInt32-over-int case is still writable. The write paths load the current Iceberg schema for field ids and manifest headers, but they keep taking stats, partition transform input, and Parquet physical encoding from the ClickHouse sample_block. For an older table whose Iceberg field is still int while ClickHouse metadata says UInt32, this still writes UINT_32 data pages and now emits 8-byte long manifest bounds/partition summaries, so the on-disk data no longer matches the table's signed-32-bit contract. Suggested fix: restore a schema-vs-sample_block compatibility check for existing tables and reject UInt32 when the persisted Iceberg field type is still int (or migrate such tables before allowing any rewrite path).
Tests
  • ⚠️ Add one focused regression for the upgrade path: attach or open a preexisting Iceberg table whose persisted schema is long/int from an older release, then verify INSERT / mutation / compaction entry points reject legacy UInt64 and legacy UInt32-over-int tables before any new data file or manifest is written. The current tests only exercise fresh tables created by the fixed code.
Final Verdict
  • Status: ❌ Block
  • Minimum required actions: reject writes through legacy UInt64 tables, reject writes through legacy UInt32 tables whose persisted Iceberg field is still int, make that validation cover every Iceberg rewrite path, and add a regression covering the upgraded-server path.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026
case TypeIndex::UInt32:
case TypeIndex::Int64:
return {"long", true};
case TypeIndex::UInt64:

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.

Rejecting UInt64 only in getIcebergType closes the bug for new CREATE / ALTER, but it does not protect legacy Iceberg tables that were already created by older releases. IcebergMetadata::write still accepts the current sample_block, getAvroType still maps UInt64 to Iceberg long (Utils.cpp:697-700), and the write path still reinterprets UInt64 as Int64 when it serializes metadata (IcebergWrites.cpp:275-277 and 668-670; Field.cpp:1057-1061 explicitly allows UInt64 <-> Int64 safeGet).

That means an upgraded server can keep writing the original broken representation for existing UInt64 tables. Please add a write-time guard for tables whose current schema still contains UInt64 (or an attach/migration guard) instead of rejecting only future DDL.

@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 7, 2026
scanhex12 added a commit that referenced this pull request Sep 30, 2026
… write `UInt32` bounds

Rejecting `UInt64` only when ClickHouse builds the schema left tables created by older
releases writable: their ClickHouse columns can still be `UInt64` over Iceberg `long`, or
`UInt32` over Iceberg `int`, and values outside the signed range were silently wrapped.
`IcebergStorageSink` now checks the columns against the current Iceberg schema and throws
for any `UInt64`, and for `UInt32` backed by an `int` field.

With that guaranteed, `UInt32` columns are always stored as `long`, so `canDumpIcebergStats`
admits `UInt32` and the 8-byte bounds from `dumpFieldToBytes` are actually written.

Address review: #118596

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
scanhex12 added a commit that referenced this pull request Sep 30, 2026
These tests declare `UInt64` columns in Iceberg tables that ClickHouse creates, which is now
rejected because Iceberg has no type for every `UInt64` value. None of them depends on the
column being unsigned.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118596&sha=ab5659415eca50326221a8d600c11413b627bf25&name_0=PR
PR: #118596

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
}
}

void checkNoUInt64(const ColumnWithTypeAndName & column)

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.

Restricting the write-time validation to UInt64 reopens the legacy UInt32 case that older releases could create. A table can still expose a ClickHouse UInt32 column over an existing Iceberg int field, but this sink no longer checks that combination before writing.

That is still unsafe in the current code:

  • the Parquet schema/data path still emits UInt32 as a 32-bit field (src/Processors/Formats/Impl/Parquet/PrepareForWrite.cpp:351, src/Processors/Formats/Impl/Parquet/Write.cpp:1336-1338);
  • the manifest path now unconditionally accepts UInt32 stats and serializes them as 8-byte long bounds (canDumpIcebergStats + dumpFieldToBytes in this file).

So INSERT into a legacy Iceberg int column can still publish data/metadata that do not match the table's signed-32-bit contract. Please keep the earlier schema-aware UInt32-over-int guard here (or reject such attachments earlier) instead of reducing the check to UInt64 only.

@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing bba9044df with master a347fefd4 (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

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

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +3.4 s (+5%) in total before that adjustment.

Job report

scanhex12 added a commit that referenced this pull request Oct 1, 2026
… insert

The insert-time check in `IcebergStorageSink` could never fire: the columns
of an Iceberg table are rebuilt from the Iceberg schema before each query,
so a `UInt64` column declared over an existing Iceberg table reaches the sink
as `Int64`. Check the declared columns in `IcebergMetadata::createInitial`
instead, before the existing-table check, so `CREATE TABLE IF NOT EXISTS`
with `UInt64` or `Array(UInt64)` over an existing Iceberg table throws too.
`ATTACH` does not go through `createInitial`, so tables created by older
releases still load.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
scanhex12 and others added 8 commits October 11, 2026 13:39
Iceberg `int` is a 32-bit *signed* integer and there are no unsigned types in
the specification at all, but ClickHouse declared a `UInt32` column as `int`:
`4294967290` was read back as `-6`. It now widens to `long`, which the
specification also allows as a promotion of `int`.

`UInt64` has no Iceberg counterpart, because `long` is the widest integer type,
so it is rejected when creating or evolving a schema. Checking the values
instead is not possible: the insert pipeline casts them to `Int64` before the
sink sees anything, and that cast wraps silently.

Existing tests that used `UInt64` for an id column now use `Int64`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
… write `UInt32` bounds

Rejecting `UInt64` only when ClickHouse builds the schema left tables created by older
releases writable: their ClickHouse columns can still be `UInt64` over Iceberg `long`, or
`UInt32` over Iceberg `int`, and values outside the signed range were silently wrapped.
`IcebergStorageSink` now checks the columns against the current Iceberg schema and throws
for any `UInt64`, and for `UInt32` backed by an `int` field.

With that guaranteed, `UInt32` columns are always stored as `long`, so `canDumpIcebergStats`
admits `UInt32` and the 8-byte bounds from `dumpFieldToBytes` are actually written.

Address review: #118596

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The limitation was edited directly inside the `AUTOGENERATED` region of `iceberg.mdx`,
which fails the docs check and would be dropped on the next regeneration. Put it into
`registerStorageObjectStorage.cpp` instead, and drop the stale claim that ClickHouse cannot
create `Decimal` Iceberg columns: it can since `Decimal` support for data lake writes, which
also makes the `Decimal(20, 0)` suggestion for `UInt64` valid.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
These tests declare `UInt64` columns in Iceberg tables that ClickHouse creates, which is now
rejected because Iceberg has no type for every `UInt64` value. None of them depends on the
column being unsigned.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=118596&sha=ab5659415eca50326221a8d600c11413b627bf25&name_0=PR
PR: #118596

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
ClickHouse tables with `UInt32` over an Iceberg `int` field, or with `UInt64`, as created by
older releases, must fail on `INSERT` instead of wrapping the values. A `UInt32` column in a
table ClickHouse creates must keep values above the `Int32` range.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…check

The insert-time check no longer compares the columns with the Iceberg schema: it only rejects
`UInt64` anywhere in the column type, which needs no schema lookup.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… insert

The insert-time check in `IcebergStorageSink` could never fire: the columns
of an Iceberg table are rebuilt from the Iceberg schema before each query,
so a `UInt64` column declared over an existing Iceberg table reaches the sink
as `Int64`. Check the declared columns in `IcebergMetadata::createInitial`
instead, before the existing-table check, so `CREATE TABLE IF NOT EXISTS`
with `UInt64` or `Array(UInt64)` over an existing Iceberg table throws too.
`ATTACH` does not go through `createInitial`, so tables created by older
releases still load.

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

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@scanhex12
scanhex12 enabled auto-merge October 11, 2026 22:14
@scanhex12
scanhex12 added this pull request to the merge queue Oct 12, 2026
Merged via the queue into master with commit f103c76 Oct 12, 2026
171 of 173 checks passed
@scanhex12
scanhex12 deleted the iceberg_unsigned_integer_types branch October 12, 2026 08:56
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 12, 2026
@clickgapai

Copy link
Copy Markdown
Contributor

@scanhex12 — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 14, 2026
… filtered in Spark

Since ClickHouse#118596 maps `UInt32` to Iceberg `long`, a `bucket[N]` partition field
whose type comes from the transform's `UInt32` result is declared Avro `long`
with 8-byte manifest-list bounds, and Spark/PyIceberg fail a read filtered on
the bucketed column (ClickHouse#125366). This PR publishes `Int32` for that field, so the
declared type stays `int` on current master as well.

- The no-Spark compaction arm now asserts the declared Avro type of the
  manifests `OPTIMIZE ... MANIFEST` writes, which it previously did not check.
- The Spark compaction test reads the table back filtered on `id = 5`.
  Iceberg projects only `=`/`IN` through `bucket`, so equality is what makes
  Spark evaluate the rewritten partition values and bounds.
- Two comments that said the manifest declares `int` "before and after this
  fix" / "keeps" the union are no longer true on master and are reworded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 15, 2026
Master now rejects `UInt64` columns on `CREATE` of an Iceberg table (ClickHouse#118596), so the test failed
before reaching the null-map statistics. The key type does not matter to what it checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Oct 17, 2026
…insert_109838`

Master now rejects `UInt64` columns on `CREATE` of an Iceberg table
(ClickHouse#118596), so
`CREATE TABLE t_u64 (c0 UInt64) ENGINE = IcebergLocal(...)` throws. The four
type-collapse cases ran as one multiquery, so the exception also skipped the
`Date` and `DateTime64(6)` cases. Remove the `UInt64` case and run each
remaining type in its own `clickhouse-local` invocation, so a failure in one
case does not hide the others.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit to groeneai/ClickHouse that referenced this pull request Oct 17, 2026
…unction_honors_structure`

Master now rejects `UInt64` columns in an Iceberg schema
(ClickHouse#118596), so
`ALTER TABLE ice17 ADD COLUMN c Nullable(UInt64)` throws and aborts the rest
of the session. Add the column as `Nullable(Int64)` instead, and declare it
the same way in the `icebergLocal` structure arguments that read `ice17`.
The values and the reference output are unchanged. The other `UInt64`
declarations in the test are table function structures, which are not
subject to the check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 26, 2026
Master now rejects UInt64 columns on CREATE of an Iceberg table (ClickHouse#118596),
so the test failed with BAD_ARGUMENTS after the merge of master. The values
are non-negative, so the reference is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
arthurpassos added a commit to Altinity/ClickHouse that referenced this pull request Nov 17, 2026
Fixes the tests that fail in CI after the backport of
ClickHouse#118596:

- `05303_optimize_empty_string_comparisons_distributed_low_cardinality`
  and `test_database_iceberg` create Iceberg tables with a `UInt64`
  column, which is now rejected. Use `Int64`.
- `test_writes_modify_column` and `test_writes_modify_column_position`
  used `UInt32` as the type that Iceberg cannot tell apart from `Int32`.
  `UInt32` is now stored as `long`, so the change is recordable. Use
  `UInt16`, which is still `int`.
@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

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.

3 participants