Skip to content

Iceberg: write a single manifest per INSERT across partitions - #128880

Merged
scanhex12 merged 10 commits into
masterfrom
iceberg-single-manifest-per-insert
Nov 4, 2026
Merged

scanhex12 merged 10 commits into
masterfrom
iceberg-single-manifest-per-insert

Conversation

@melvynator

@melvynator melvynator commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Each INSERT used to write one manifest file per partition it touched, so a daily-partitioned backfill of N days produced N manifests (401 vs 1 for Spark/PyIceberg on the same data). Now one manifest holds entries for every partition; each entry carries its own partition tuple and the manifest-list summary aggregates contains_null/contains_nan/lower/upper bounds over them. ALTER TABLE ... DROP PARTITION learns to rewrite a data manifest shared with other partitions (surviving entries are kept as EXISTING with their original lineage) instead of throwing NOT_IMPLEMENTED. We probably want to check how it will also work with compaction

image

Changelog category (leave one):

  • Improvement

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

This feature will reduce the number of manifest files written when writting across multiple partition. Today ClickHouse writes one file per partition. This might lead to a less optimal metadata layout. ClickHouse will instead write only one manifest files but with a partition breakdown within the file.


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

Version info

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

Each INSERT used to write one manifest file per partition it touched, so a
daily-partitioned backfill of N days produced N manifests (401 vs 1 for
Spark/PyIceberg on the same data). Now one manifest holds entries for every
partition; each entry carries its own partition tuple and the manifest-list
summary aggregates contains_null/contains_nan/lower/upper bounds over them.
ALTER TABLE ... DROP PARTITION learns to rewrite a data manifest shared with
other partitions (surviving entries are kept as EXISTING with their original
lineage) instead of throwing NOT_IMPLEMENTED. We probably want to check how
it will also work with compaction
@melvynator
melvynator requested a review from scanhex12 November 3, 2026 03:52
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [ff80d06]

Summary: ✅


AI Review

Summary

The PR adds opt-in Iceberg manifests spanning multiple partitions per insert stream, extends manifest compaction to consolidate across partitions, and preserves per-file partition tuples during full compaction. Reviewed head: ff80d06db9f1d7f516cdfc7a730942bcf2cacb45. Request changes because full compaction still publishes incorrect per-file statistics. No new independent inline findings were identified; the two outstanding points below were previously dismissed and remain summary-only.

PR Metadata

The Improvement category is appropriate and requires a user-readable changelog entry. The current entry incorrectly describes the layout change as automatic, although iceberg_insert_single_manifest_for_all_partitions defaults to false. The introductory description also claims shared manifests can be rewritten by ALTER TABLE ... DROP PARTITION, which the current code rejects.

Replace the changelog entry with:

Added the iceberg_insert_single_manifest_for_all_partitions setting, disabled by default, to combine files from different partitions into one Iceberg manifest per insert stream and consolidate manifests across partitions with OPTIMIZE TABLE ... MANIFEST. Use max_insert_threads = 1 for exactly one manifest per INSERT. ALTER TABLE ... DROP PARTITION remains unsupported when the selected partition shares a manifest with other partitions.

Replace the introductory description with:

Add optional Iceberg manifests spanning multiple partitions, with aggregated partition summaries and preserved per-file partition tuples during compaction. Shared-manifest partition dropping remains unsupported.

Missing context / blind spots
  • ⚠️ Runtime reproduction was not performed because this checkout has no ClickHouse binary or build directory. The current-head Praktika report contains no targeted stateless or integration test results. Successful execution of 05494, 05495, 05496, and the modified Spark interoperability test would close that validation gap.
Findings

⚠️ Majors

  • Compaction.cpp:1324 — Per-file statistics must describe the file they accompany. Full compaction accumulates every file's statistics into ManifestFilePlan::statistics at lines 439 and 454, then supplies that same accumulator to every rewritten entry. With shared manifests, statistics from different partitions are mixed even with one file per partition. For example, insert (NULL,1),(NULL,2),(1,3) together into (p Nullable(Int64), n Int64) partitioned by p, using the new setting and max_insert_threads = 1; insert (2,4),(2,5) separately, delete n = 4, then run full OPTIMIZE TABLE. The rewritten file for p = 1 receives record_count = 1 and null_value_counts[p] = 2, although it has no nulls. Column sizes are likewise manifest-wide. Collect statistics per output file after applying deletes and pass them through per_file_fresh_statistics.
    [dismissed by author -- https://github.com/Iceberg: write a single manifest per INSERT across partitions #128880#discussion_r4457812943]
    Still valid: the current call continues to pass the shared accumulator without per-file statistics.

💡 Nits

  • Settings.cpp:10394 / PR description — The changelog promises default consolidation and the introduction promises shared-manifest partition dropping. Apply the replacement text above.
    [dismissed by author -- https://github.com/Iceberg: write a single manifest per INSERT across partitions #128880#discussion_r4456737277]
    Still valid: the setting remains disabled by default, and AlterDropPartitionExecutor.cpp:742 rejects partial-manifest drops.
Tests
  • ⚠️ Add a focused stateless regression for full compaction of a shared manifest with nullable values across partitions. Assert each rewritten file's null counts and column sizes after deletion; 05495 currently verifies only partition tuples and query results.
Final Verdict

Status: ⚠️ Request changes. Compute full-compaction statistics per output file and cover them with the focused regression. Correct the PR description and changelog as described above.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing ff80d06db with master 77c29e32d (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

11 object files changed (+31.25 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o 1.03 MiB 1.06 MiB +24.04 KiB (+2.27%)

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

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

Job report

@scanhex12 scanhex12 self-assigned this Nov 3, 2026
scanhex12 and others added 2 commits November 3, 2026 13:36
Keep one manifest per INSERT for all partitions, with a `ManifestPartitionSummary`
that aggregates `contains_null`/`contains_nan`/bounds over the entries' partition tuples.

- Data compaction (`OPTIMIZE TABLE`) mapped each source manifest to a single partition
  (the last one seen) and stamped it on every file of the rewritten manifest. With
  multi-partition manifests this mislabels files and partition pruning skips data.
  Each file now keeps its own partition, and the manifest list gets partition summaries.
- `OPTIMIZE TABLE ... MANIFEST` grouped by partition value, so it either reported
  "already optimal" or split a table back into one manifest per partition. It now
  groups by (partition spec, schema), with per-entry partition tuples.
- `ALTER TABLE ... DROP PARTITION` rewrites a manifest shared with other partitions:
  surviving entries are written as EXISTING with their original lineage and stats,
  under the schema the manifest was written with. Manifests with per-file
  `key_metadata` are rejected, as in manifest compaction.
- `getColumnStatisticsForRewrite`, `getEntryLineageForRewrite` and
  `manifestHasKeyMetadata` are shared between manifest compaction and DROP PARTITION.
- The Spark integration test now checks that a shared manifest is rewritten and that
  Spark reads a multi-partition manifest written by ClickHouse.

Related: #128880

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

mintlify Bot commented Nov 3, 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 Nov 3, 2026, 3:11 PM

…in DROP PARTITION

- New setting `iceberg_insert_single_manifest_for_all_partitions` (default `false`).
  When enabled, an `INSERT` writes one manifest for all the partitions it touches;
  otherwise it writes one manifest per partition, as before.
  `OPTIMIZE TABLE ... MANIFEST` follows the same setting: without it, manifests are
  still consolidated per partition, so DROP PARTITION keeps working on them.
- `ALTER TABLE ... DROP PARTITION` is back to the `master` behavior: dropping a
  partition whose manifest is shared with other partitions throws `NOT_IMPLEMENTED`.
- Data compaction keeps each file's own partition value regardless of the setting.
- `05045` and `05229` are back to the `master` versions, since the default layout is
  unchanged. `05494` enables the setting and checks the DROP PARTITION rejection.
- New test `05495` checks that data compaction keeps the partition of each file of a
  manifest shared by several partitions.

Related: #128880

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l inserts

Every `IcebergStorageSink` commits its own snapshot, and an `INSERT` runs one sink per
insert stream (`IcebergMetadata::supportsParallelInsert`). So with
`iceberg_insert_single_manifest_for_all_partitions` each stream writes one manifest for
all the partitions it received, and the whole `INSERT` writes exactly one manifest only
with `max_insert_threads = 1`. Say so in the setting and in the `DROP PARTITION` docs.

`05494` now also runs an `INSERT SELECT` with `max_insert_threads = 4`: each of its
snapshots adds exactly one manifest, and every manifest spans all partitions.

Related: #128880

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Fix `clang-diagnostic-missing-designated-field-initializers` in `ManifestPartitionSummary`
  (Build (arm_tidy, 3/4)).
- The note about `iceberg_insert_single_manifest_for_all_partitions` and `DROP PARTITION`
  belongs to the documentation registrations in `registerStorageObjectStorage.cpp` and
  `TableFunctionObjectStorage.cpp`, not to the generated `docs/reference` pages, which are
  restored.
- New test `05496` covers `OPTIMIZE TABLE ... MANIFEST` across partitions: with the setting,
  three manifests spanning different partitions are merged into one with every file's
  partition and lineage preserved, aggregate bounds and counts, and correct filtered reads;
  without it, one manifest per partition is kept.

Related: #128880

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Core/Settings.cpp Resolved
With `max_insert_threads = 4` the insert streams race to commit the next metadata version.
The loser logs `FILE_ALREADY_EXISTS` from `writeMetadataFile` as an error and retries, so the
result is correct, but the client forwards the log to stderr and the test fails with
"having stderror". Run that `INSERT` with `send_logs_level = fatal`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=128880&sha=ed3227f2a83e0b73aa23b5a7083ce2af76f35f24&name_0=PR&name_1=Stateless%20tests%20%28arm_asan_ubsan%2C%20targeted%29
Related: #128880

Co-Authored-By: Claude Opus 5.5 <[email protected]>
scanhex12 and others added 2 commits November 3, 2026 18:43
Manifest compaction is its only user since `DROP PARTITION` no longer rewrites manifests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…into `Compaction.cpp`

Manifest compaction is their only user.

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

Collect each partition's files into the pending manifest and write it after every
partition, or once at the end with `iceberg_insert_single_manifest_for_all_partitions`.
The manifest-writing failures are already cleaned up by the enclosing commit attempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@scanhex12
scanhex12 added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit f5b7251 Nov 4, 2026
186 checks passed
@scanhex12
scanhex12 deleted the iceberg-single-manifest-per-insert branch November 4, 2026 08:31
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 4, 2026
…-iceberg-nan-manifest-pruning

Master ClickHouse#128880 moved the per-entry statistics copy of the manifest-only
rewrite (OPTIMIZE TABLE ... MANIFEST) into getColumnStatisticsForRewrite.
The nan_value_counts carry now lives in that helper; no other change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 5, 2026
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]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 8, 2026
…t-list-bucket-partition-summary

Conflict in IcebergWrites.cpp: master (ClickHouse#128880) now aggregates the
manifest-list partition summary over all entries of a manifest
(`ManifestPartitionSummary`, with `bounds_unavailable` per field)
instead of passing one (value, type) pair per field.
`canWritePartitionSummary` now checks `bounds_unavailable`, so a
manifest with any value that has no Iceberg bound serialization still
omits the optional `partitions` field rather than publishing a field
summary without bounds, which readers take as "only nulls or NaNs".
The write loop takes master's form; its `bounds_unavailable` check and
comment are dropped because the guard above already returns early.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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-improvement Pull request with some product improvements 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