Skip to content

Merge Iceberg manifests on append - #128472

Open
alexey-milovidov wants to merge 24 commits into
masterfrom
iceberg-merge-manifests-on-append
Open

alexey-milovidov wants to merge 24 commits into
masterfrom
iceberg-merge-manifests-on-append

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Related: #98178

Every INSERT into an Iceberg table adds new manifests and carries all the manifests of the parent snapshot forward, so the number of manifests grows with the number of inserts. Reading manifests is a large part of the work of every query, and for many small manifests it is pure startup delay and cost, while it is easy to avoid: manifests are small, so merging them is cheap. OPTIMIZE TABLE ... MANIFEST (#98178) does this only on request and as a separate snapshot.

Like other Iceberg writers (MergeAppend in the reference implementation), INSERT now merges the small data manifests of the parent snapshot into fewer ones as part of the same commit, without any experimental setting. The new append snapshot lists the same data files as EXISTING entries keeping their snapshot ids, sequence numbers, statistics and partition tuples, so no data is read and no separate snapshot is created; older snapshots keep their own manifests.

  • The merge happens when the new snapshot would have more small data manifests than the table property commit.manifest.min-count-to-merge, or, when it is not set, the iceberg_manifest_min_count_to_compact setting (default 100).
  • Merged manifests span partitions (otherwise a table with one insert per partition would never shrink), ordered by partition so the manifest-list partition bounds stay narrow, and hold up to the entries that fit in commit.manifest.target-size-bytes (default 8 MiB). Manifests that already hold at least half of that are carried forward as they are, so the cost of a merge stays bounded.
  • commit.manifest-merge.enabled = false disables it. It is done only for format version 2, and skipped (not failed) for encrypted data files and for partition values that cannot be written (including binary and nested partition source columns); delete manifests are always carried forward unchanged.
  • ALTER TABLE ... DROP PARTITION rewrites a data manifest that also lists files of other partitions (such as a merged one) without the dropped files, instead of failing. The full OPTIMIZE TABLE compaction rejects, before writing anything, a history where a data file is listed in several manifests (a merged one and the originals kept by older snapshots).

The collection and rewriting of data manifests moves from OPTIMIZE TABLE ... MANIFEST into a shared DataManifestsRewriter; OPTIMIZE keeps writing one manifest per partition, or one per partition spec and schema with iceberg_insert_single_manifest_for_all_partitions (#128880). The manifest-list partition summary as a range and per-file partition tuples in generateManifestFile come from that PR. A manifest written with that setting can now also be handled by ALTER TABLE ... DROP PARTITION.

Related: #128880

Measurements {#measurements}

Workload: CREATE TABLE t (k Int64, p Int64, s String) ENGINE = IcebergS3(<local MinIO>, 'Parquet') PARTITION BY p, then 300 separate INSERT INTO t SELECT number + i * 1000, i % 10, 'x' FROM numbers(100) from one clickhouse local session, then 11 runs of SELECT count(), sum(k) FROM t WHERE p = 3 with use_iceberg_metadata_files_cache = 0 (first run discarded). Merge enabled: iceberg_manifest_min_count_to_compact = 100 (the default); merge disabled: iceberg_manifest_min_count_to_compact = 1000000. The same with 500 inserts on a local disk (IcebergLocal). The machine was shared (load average 40–90), so wall-clock times are noisy; request and byte counts are exact.

merge enabled merge disabled
manifests in the final snapshot (500 inserts, local disk) 5 500
manifest-list bytes written in total (500 inserts, local disk) 5.9 MB 22.1 MB
manifest bytes written in total (500 inserts, local disk) 5.3 MB 4.9 MB
SELECT: S3 GetObject per query 37 66
SELECT: bytes read from S3 per query 1.53 MB 1.84 MB
SELECT: median time, S3 (noisy) 0.077 s / 0.246 s (two runs) 0.081 s
SELECT: median time, local disk 0.070 s 0.080 s
300 inserts: S3 GetObject in total 1195 / 1104 (two runs) 870
300 inserts: S3 PutObject in total 1203 / 1079 1160
300 inserts: bytes read / written on S3 61.7 / 59.7 MB 66.6 / 63.4 MB
insert latency, median, S3 (noisy) 0.406 s / 0.324 s 0.298 s
insert latency, median, local disk 0.107 s 0.108 s

With merging, a query reads about half as many objects here (the manifest-list partition bounds already prune most manifests of other partitions; without them the difference grows linearly with the number of inserts), and the manifest lists written by every insert stay small. The cost on the insert side is about one extra GetObject per insert (the parent manifest list read to decide whether to merge) plus, once per ~100 inserts, reading and rewriting the small manifests; the total bytes moved per insert are slightly lower. The insert-latency difference on S3 is within the noise of the shared machine (the two enabled runs differ by 25%).

Changelog category (leave one):

  • Performance Improvement

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

INSERT into an Iceberg table merges the small manifest files of the current snapshot within the same commit when there are more than commit.manifest.min-count-to-merge (or the iceberg_manifest_min_count_to_compact setting, 100 by default) of them, so the number of manifests a query has to read no longer grows with the number of inserts. The merge can be disabled with the table property commit.manifest-merge.enabled = false.

🤖 Generated with Claude Code


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

Every `INSERT` into an Iceberg table adds new manifests and carries all the
manifests of the parent snapshot forward, so their number grows with the
number of inserts, and so does the startup cost of every query, which has to
read all of them. Like the reference implementation's `MergeAppend`, an append
now merges the small data manifests of the parent snapshot into fewer ones as
part of the same commit. The data files are listed as EXISTING entries keeping
their lineage, statistics and partition tuples, so no separate snapshot is
created and no data is read.

- The merge happens when the new snapshot would have more small data
  manifests than the table property `commit.manifest.min-count-to-merge`, or
  the `iceberg_manifest_min_count_to_compact` setting (default 100).
- Merged manifests span partitions, ordered by partition so the manifest-list
  bounds stay narrow, and hold up to the entries that fit in
  `commit.manifest.target-size-bytes` (default 8 MiB). Manifests holding at
  least half of that are carried forward as they are, so a merge never
  rewrites large parts of the metadata again.
- `commit.manifest-merge.enabled` = `false` disables it. It is done only for
  format version 2, and skipped for encrypted data files and partition values
  that cannot be written, so an `INSERT` never fails because of it.

The collection and rewriting of data manifests is moved from `OPTIMIZE TABLE
... MANIFEST` into `DataManifestsRewriter`, shared by both. `OPTIMIZE` keeps
writing one manifest per partition. The manifest-list partition summary is
now a range, and `generateManifestFile` accepts per-file partition tuples.

Related: #98178

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

clickhouse-gh Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b0f93e1]

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 1, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Nov 1, 2026
alexey-milovidov and others added 3 commits November 3, 2026 01:02
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…er manifests are merged

- `ALTER TABLE ... DROP PARTITION` now rewrites a data manifest that also lists files of other
  partitions (e.g. one merged by an `INSERT`) without the dropped files, using `DataManifestsRewriter`,
  instead of throwing `NOT_IMPLEMENTED`. Partially matched delete manifests are still rejected.
- Full `OPTIMIZE TABLE` rejects, before anything is written, a history where a data file is listed
  in several manifests (a merged one and the originals kept by older snapshots). It assigns each
  data file to its first manifest only, so it would drop the files from the other manifests and
  then delete the originals.
- The merge on append also checks the resolved partition types with `canGetAvroType`, not only the
  `Field` carriers, so e.g. an old `fixed` identity partition skips the merge instead of failing the
  `INSERT` in `getAvroType`.

The test covers `DROP PARTITION` and full `OPTIMIZE` after a merge.

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

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5ea98ff0e with master 4c070eb09 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

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 ⚠️

10 object files changed (+714.91 KiB total), 1 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/DataManifestsRewriter.cpp.o new 667.67 KiB +667.67 KiB
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o 1.34 MiB 1.44 MiB +105.10 KiB (+7.67%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp.o 1.14 MiB 1.05 MiB -84.77 KiB (-7.29%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/AlterDropPartitionExecutor.cpp.o 715.38 KiB 739.45 KiB +24.07 KiB (+3.36%)

716 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

60 translation units recompiled, 489 s compile time in total, 59 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Storages/ObjectStorage/DataLakes/Iceberg/DataManifestsRewriter.cpp: 8.2 s

Job report

alexey-milovidov and others added 2 commits November 4, 2026 07:52
…ite `Float32` partition values as Avro `float`

- Full `OPTIMIZE TABLE` wrote one partition tuple per rewritten manifest, so a manifest listing data files
  of several partitions (a single Spark append, or manifests merged by an `INSERT` whose original
  snapshots have expired) got a wrong partition value for some files, breaking partition pruning and
  identity-column projection. It now passes the partition tuple of each data file to
  `generateManifestFile`.
- `generateManifestFile` built a `double` datum for `Float32` partition values, which the Avro writer
  encodes as eight bytes where readers expect a four-byte `float`, corrupting the manifest written by a
  merge of manifests with a `float` identity partition. It now builds a `float` datum when the
  manifest schema field is `float`.
- `test_drop_partition_shared_spark_manifest_is_rejected` pinned the old `NOT_IMPLEMENTED` rejection of
  `DROP PARTITION` on a manifest spanning partitions; this PR rewrites such manifests instead, so the
  test now checks the result and that Spark reads it.
- New tests: merge, expire the original snapshots, position delete, full `OPTIMIZE`; and Spark
  `float`-partitioned manifests merged by a ClickHouse `INSERT` after the spec became unpartitioned.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=f657285adeae8109e0279123c0dbf6b29c37c2c5&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29
PR: #128472

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits November 5, 2026 14:18
Reconcile with #128880 (single manifest per `INSERT`),
which also introduced per-file partition tuples in `generateManifestFile` and a range partition summary:
- Use master's `ManifestPartitionSummary` class and the required `per_file_partition_values` argument
  of `generateManifestFile`; drop this branch's duplicates of them.
- Keep master's full-compaction handling of manifests spanning several partitions.
- `OPTIMIZE TABLE ... MANIFEST` keeps using `DataManifestsRewriter`, with `Grouping::SpanPartitions`
  when `iceberg_insert_single_manifest_for_all_partitions` is set, as on master.
- `ALTER TABLE ... DROP PARTITION` rewrites a manifest shared with other partitions (this branch), so the
  tests and the setting description that expected `NOT_IMPLEMENTED` for it are updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion sources

`DataManifestsRewriter` derives the partition types from the ClickHouse types, which do not tell an
Iceberg `binary` from a `string`, so a merged manifest would declare a `binary` partition value as Avro
`string`. It also resolved the partition sources through `ChunkPartitioner`, which knows only the
top-level columns, so an old spec partitioned by a nested column made the append-time merge throw
`NOT_FOUND_COLUMN_IN_BLOCK` and fail the `INSERT`.

Such specs are now reported by `hasUnsupportedPartitionValues`: the `INSERT` skips the merge,
`DROP PARTITION` and `OPTIMIZE TABLE ... MANIFEST` throw `NOT_IMPLEMENTED` before writing anything.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=c989bf47d68d7a9cbfcbdb3d6ff5a51a1561ccd0&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20AsyncInsert%2C%20s3%20storage%2C%20parallel%29 (03237_insert_sparse_columns_mem, reproducible with the randomized setting min_chunk_bytes_for_parallel_parsing = 171302, unrelated to Iceberg) and provide a fix in a separate PR. If the fix is already in progress, link it here.

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Acknowledged. No fix for this is in progress yet (no open PR touches 03237_insert_sparse_columns_mem). I'm investigating it with min_chunk_bytes_for_parallel_parsing = 171302 and will follow up here with a fix PR (or my findings) shortly.

@groeneai

groeneai commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

The fix is in #129574. The failure is not about the test: under async_insert = 1, AsyncInsertQueueTransform replayed a materialized copy of the first block into the synchronous fallback, so with that chunk size the whole insert block lost its sparse columns (10165446 written bytes instead of about 340000).

alexey-milovidov and others added 2 commits November 7, 2026 01:13
…anifest rewrites

The shared `DataManifestsRewriter` (used by the merge of manifests on `INSERT`,
`OPTIMIZE TABLE ... MANIFEST` and `ALTER TABLE ... DROP PARTITION`) declared the
manifest partition fields and encoded the manifest-list partition bounds from the
return types of the transform functions, which are not the Iceberg partition
types: `icebergBucket` returns `UInt32`, which was written as Avro `long` with
8-byte bounds, while a bucket partition is an Iceberg `int`; a `uuid` identity
partition was declared as `string` instead of `fixed[16]`.

The partition types are now derived from the Iceberg types of the transform
results: integer types are narrowed or widened to the Iceberg `int`/`long`, and a
spec whose partition values cannot be written with the physical type the spec
requires (e.g. `uuid`, `binary`, `fixed`) is not rewritten.

Rewritten entries also lost their `split_offsets`; they are now carried over.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…flight partition transforms before reading manifests

- Expiring snapshots with metadata cleanup can remove a schema from the metadata while live manifests are still
  written under it. `getSchemaObjectById` now takes such a schema from `IcebergSchemaProcessor`, where the manifest
  header registered it, and keeps preferring the authoritative copy in the metadata.
- Reading a manifest instantiates the transform functions of its partition spec, and `ChunkPartitioner` does too.
  `icebergTruncate` rejects e.g. `truncate[10]` of a `decimal(20, 2)`, so an append failed with
  `ILLEGAL_TYPE_OF_ARGUMENT` when an old spec like that crossed the merge threshold. `collect` now checks the spec
  of each manifest first, and the manifests of an unsupported spec are kept as they are. `OPTIMIZE TABLE ... MANIFEST`
  reports such a table as unsupported rather than as having nothing to do.

Both cases are covered by a Spark integration test.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128472&sha=7d3c4efb51731de1f1f13b27344be6f8e4645e81&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%206%2F6%29 (array_join query flagged as a regression; this PR only changes Iceberg manifest writing) and provide a fix in a separate PR. If the fix is already in progress, link it here. The Build profile diff failure (LogClusterNotReady) is tracked by #129675.

@groeneai

Copy link
Copy Markdown
Collaborator

Acknowledged. The flagged query is array_join #1 (LEFT ARRAY JOIN a, b over numbers(10000000), 0.111 s -> 0.128 s, +15%, +16.8% after the server restart), and no open PR addresses it yet. I'm investigating it and will follow up here with a fix PR (or my findings) shortly.

@groeneai

Copy link
Copy Markdown
Collaborator

The array_join #1 red is not from this PR. In the job's own CPU profile all of the extra time is in emptyArrayToSingle, which LEFT ARRAY JOIN runs over every joined array: its per-row loop +30% and its per-row memcpy calls +76% of samples, every other frame equal. Its machine code is identical in both binaries, only at another address (0x1fe3bd00 in the reference, 0x1fe4f100 here), and the slowdown survived the restart at all three stack placements. No merged PR introduced it, so there is nothing to revert.

#130581 makes emptyArrayToSingle return its argument as is when no array is empty, so this query no longer runs that loop (about 1.6x faster in my local A/B).

…blished

The check of the partition transforms before reading a manifest searched only
top-level fields of the schemas of the metadata and accepted a spec when it did
not find the source column. A source nested in a struct, or a dropped column
whose schemas were expired, then reached `buildPartitionKeyFromSpec`, which
instantiated `icebergTruncate` and threw. A spec whose source type cannot be
established is now treated as unsupported (except for `void`).

The manifests of an unsupported spec were also treated as empty when the
manifest list reported zero live files, but the counts are optional in v1
manifest lists and a missing or null count is read as zero. The rewrite would
then drop the data of such manifests from the snapshot. Now an unsupported
manifest is only skipped when the statuses of its entries, which are read
without the spec, show that it has no live entries.

The integration test of the historical `truncate` of `decimal(20, 2)` is
extended to a source nested in a struct.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/128472/66b011f8b82b06df7e21b1a0a441709b167bfcea/pr/ast_fuzzer_amd_release_oracle/job.log (AST fuzzer (amd_release, oracle): TLP Aggregate oracle mismatch for WHERE arrayAll(x -> ((a = x) OR (x = 4242)), [b]) on t_qcc_lambda__fuzz_26 with use_query_condition_cache=true) and provide a fix in a separate PR. It is unrelated to this Iceberg PR and looks like the query condition cache issue with lambdas that capture a column, which #122966 addresses. If the fix is already in progress, link it here.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, there was an outage, so this request may have been missed. Please take a look at #128472 (comment)

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@groeneai, a reminder about this request after the outage: #128472 (comment)

@groeneai

Copy link
Copy Markdown
Collaborator

The fix is #122966 (mine, open). This is the same query condition cache key collision: a lambda that captures a column is keyed by its signature, arrayAll(Capture[Nullable(Int128), UInt16](Nullable(Int64)) -> Nullable(UInt8)(a, 4242_UInt16), array(b)), without its body.

In this run's server.log, the fuzzed arrayAll(x -> ((x = a) AND (4242 = x)), [b]) (05:19:30.38) wrote the entry for t_qcc_lambda__fuzz_26. The next query, arrayAll(x -> ((a = x) OR (x = 4242)), [b]), logged Query condition cache has dropped 131/139 granules for the same key and read 65536 of 1000000 rows.

The same pair on a server (a Nullable(Int128), b Nullable(Int64), ORDER BY a, 1M rows number, number), AND query, then OR query:

#122966 got a master merge today to resolve a conflict in ActionsDAG::Node::updateHash; CI is running on that head. It has no review yet.

alexey-milovidov and others added 2 commits November 14, 2026 09:49
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…ce column is gone

The Iceberg spec allows a `void` partition field to reference a source column
that was dropped later, and the schemas that defined it may be expired from the
metadata. Such manifests are readable, but `DataManifestsRewriter::resolvePartitionSpec`
threw `ICEBERG_SPECIFICATION_VIOLATION` because no schema defines the source,
so an otherwise writable `INSERT` failed once it crossed the manifest merge
threshold. Mark the spec as not rewritable instead, so the manifests are carried
forward unchanged (and `OPTIMIZE ... MANIFEST` / `DROP PARTITION` report it as
unsupported). Other missing source columns are still reported as an error.

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

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai. I agree the AST fuzzer oracle mismatch (query condition cache key collision for lambdas) is unrelated to this PR and is covered by #122966. The other red result, the low_cardinality_argument perf query, is also outside the Iceberg code this PR touches. I merged master to resolve the conflict and pushed, so CI is running again.

…schema defines all its sources

A historical spec such as `void(a), identity(b)` can reference sources that never
coexisted in one schema (`a` dropped before `b` was added). The previous check only
looked whether each `void` source exists in some schema, so it fell through to the
`ICEBERG_SPECIFICATION_VIOLATION` exception. Now, if no schema defines all source
columns of a spec that has a `void` field, the spec is marked as not rewritable and
its manifests are kept unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
grantholly-clickhouse pushed a commit to il9ue/ClickHouse that referenced this pull request Nov 16, 2026
…ynchronous insert

AsyncInsertQueueTransform held a materialized copy of the first block of an
INSERT ... SELECT under async_insert (const, sparse and replicated columns
converted to full). When a second block arrived, that copy was replayed into
the synchronous fallback pipeline, so CountingTransform counted the first block
at full size and Squashing, seeing chunks of different structures, materialized
every chunk of the squashed block. For a wide table with sparse columns this
wrote a full part and used about 6 times more memory.

This is what fails 03237_insert_sparse_columns_mem in the AsyncInsert job with
min_chunk_bytes_for_parallel_parsing = 171302: the first parsed segment is 4953
rows, small enough to be held, and the second insert reports 10165446 written
bytes instead of about 340000.

Hold the original chunk and materialize a copy only when the block is diverted
to the queue. A block whose materialized size exceeds async_insert_max_data_size
now falls back with the original chunks at the end of input, after the existing
kill / timeout / cancel guard, which therefore covers both exits of a held
block. The replay part of disqualify() is split out as fallBack().

The new test compares the bytes written by the async fallback with a plain
synchronous INSERT ... SELECT of the same blocks. Its source table pins
index_granularity: a granule of 20000 rows or more is read as one block, which
the queue route diverts instead of falling back.

Related: ClickHouse#128472

Co-Authored-By: Claude Opus 5.5 <[email protected]>
grantholly-clickhouse pushed a commit to il9ue/ClickHouse that referenced this pull request Nov 16, 2026
…t assert its route

The previous commit moved materializeBlockInplace in getRemaining below the
kill / timeout / cancel guard, so an O(block) expansion ran between the last
check and the write. Materialize first and keep the guard right before both
writes (the divert to the queue and the fallback of a block that is too large
after materialization), as it was before. The rejected materialized copy is now
released before the fallback runs.

The test now also fails when its evidence is missing: it requires both
query_log rows and the text_log line showing that the async query took the
queue route and fell back there (async_insert_select_as_async_insert = 0 gives
0 for that line).

Related: ClickHouse#128472

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 4 commits November 19, 2026 06:03
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/Utils.cpp
…under another partition spec

Full compaction rewrites every data file under the default partition spec and reuses its partition tuple as is.
The arity check let a file of another spec with the same number of fields through, e.g. `identity(a)` after the
default spec changed to `identity(b)`, and the rewritten file then declared values of `a` as values of `b`, so
partition pruning and identity-column projection could return wrong results. Now each data file must have the same
source columns and transforms as the default spec, otherwise `OPTIMIZE` fails with `NOT_IMPLEMENTED` before
anything is written.

`test_optimize_position_delete_other_partition_spec` compacted an `identity(region)` file under
`truncate(1, region)`, which only kept the right partition value by coincidence; it now expects the refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n_spec_of_another_source`

Spark merged the manifests of the table, so a data file was listed in two manifests and `OPTIMIZE` was refused by the
duplicate-manifest check before it reached the partition spec check the test is about.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
clickhouse-gh[bot]
clickhouse-gh Bot previously approved these changes Nov 19, 2026
@clickhouse-gh
clickhouse-gh Bot dismissed their stale review November 19, 2026 08:54

AI review of a later commit does not approve the PR, see the AI Review comment.

@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 19, 2026
alexey-milovidov and others added 2 commits November 22, 2026 12:54
…ests-on-append

Conflicts in `Compaction.cpp` and `IcebergWrites.cpp` are unions of both sides: the manifest merge on `INSERT`
and the partition-spec check of the compaction from this branch, the NDV table statistics and the new insert
settings from master.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…anifest rewrite

`icebergTruncate` of a `decimal(5, 2)` returns `Decimal(9, 2)`, the widest precision of the same carrier, and both
are an Avro `fixed`, so `getManifestPartitionType` accepted the widened type and the merged manifest declared
`decimal(9, 2)` in four bytes instead of the `decimal(5, 2)` in three bytes of the partition spec. The partition
type of `identity` and `truncate` of a decimal is now built from the precision and scale of the Iceberg source
type, and the spec is not rewritten if the transform returns another scale or carrier.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
alexey-milovidov and others added 2 commits November 25, 2026 04:43
# Conflicts:
#	src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp
…nifest rewrite

`getManifestPartitionType` applied the decimal precision handling whenever the
source column was a decimal, so for `bucket[N]` of a `decimal(P, S)`, whose result
is an Iceberg `int`, it returned no type: the transform returns `UInt32`, which is
not a decimal. Such manifests were never merged on `INSERT`, and they disabled the
merge of the other candidates as well.

Apply the precision handling only when the partition type is the decimal itself
(the required Avro type is `fixed`), and let the `bucket` take the integer path.

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

Copy link
Copy Markdown
Member Author

🕵 Merged master (one conflict in IcebergWrites.cpp: both sides added an include and a setting declaration, kept both). The only CI failure, Logical error: Directory 'A' is virtual (STID: 6611-5d35) in La Casa Del Dolor (amd_tsan) (report), is in the plain_rewritable metadata storage (DiskObjectStorage::replaceFile) and is unrelated to this change; #132449, merged on 2026-11-22, addresses it and is now in the branch through the merge.

This branch has not been deployed

No deployments
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-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants