Skip to content

DROP PARTITION for iceberg tables - #105198

Closed
Diskein wants to merge 91 commits into
masterfrom
dk-iceberg-alter-drop-partition
Closed

Diskein wants to merge 91 commits into
masterfrom
dk-iceberg-alter-drop-partition

Conversation

@Diskein

@Diskein Diskein commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

Closes: #97929

Implements ALTER TABLE ... DROP PARTITION (...) for Iceberg v2 tables, e.g.
ALTER TABLE my_iceberg DROP PARTITION (2, '2'). The partition expression accepts the
same literal/tuple/transform forms as the partition spec (e.g. icebergBucket, date transforms).

Behaviour:

  • Drops the partition as of query start; rows inserted into the same partition while it runs are kept.
  • Removes a fully-matched data manifest outright, and rewrites a partially-matched one to keep
    the survivors.
  • Supports both catalog-backed (DataLakeCatalog) and path-based tables.

Limitations:

  • Requires the experimental allow_insert_into_iceberg setting.
  • Iceberg format-version 2 only.
  • Tables with evolved partition specs, or where a surviving file was written under a different
    schema than the table's current one (schema evolution).
  • An affected manifest containing equality deletes.
  • decimal, UUID, and boolean partition columns.
  • Throws a write conflict if a concurrent rewrite/compaction replaces the targeted files.

Changelog category (leave one):

  • New Feature

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

Support ALTER TABLE ... DROP PARTITION (...) on Iceberg v2 tables, e.g. ALTER TABLE my_iceberg DROP PARTITION (2, '2').

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@scanhex12 scanhex12 self-assigned this May 18, 2026
@Diskein
Diskein force-pushed the dk-iceberg-alter-drop-partition branch from b3d1b3d to cb241f6 Compare May 19, 2026 13:50
@clickhouse-gh

clickhouse-gh Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5997c12]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DBReplicated, WasmEdge, parallel, 2/3) FAIL
Server died FAIL cidb
02354_vector_search_queries UNKNOWN cidb
03417_http_exception_tag UNKNOWN cidb
00626_replace_partition_from_table UNKNOWN cidb
03915_exchange_tables_race UNKNOWN cidb, issue
01083_cross_to_inner_with_like UNKNOWN cidb
00575_illegal_column_exception_when_drop_depen_column UNKNOWN cidb
01925_broken_partition_id_zookeeper UNKNOWN cidb
04011_compress_per_column_in_compact_parts UNKNOWN cidb
Unknown error FAIL cidb
Integration tests (amd_tsan, 3/6) FAIL
test_replicated_database/test.py::test_replicated_table_structure_alter FAIL cidb, issue
Stress test (arm_release) FAIL
Logical error: Trying to extract chunk from ChunkBuffer before all inputs are finished (STID: 4752-5cbf) FAIL cidb

AI Review

Summary

This PR adds ALTER TABLE ... DROP PARTITION for Iceberg tables by discovering the target files, rewriting partially matched manifests, and committing a new snapshot. The core flow is much closer after the follow-up fixes already on the PR, but I still see two correctness blockers in the current head, one new manifest-list metadata regression, and one remaining documentation gap.

Findings

❌ Blockers

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/AlterDropPartitionExecutor.cpp:824] commitMetadataJSON writes vN.metadata.json and may advance version-hint.text before catalog->updateMetadata runs for non-transactional catalogs. GlueCatalog::updateMetadata throws on remote failures, and the executor's cleanup path only removes the manifest list / replacement manifests, not the newly published metadata file or hint. A failed catalog commit can therefore leave object-storage readers discovering a metadata file that points at manifests we already deleted. Suggested fix: for non-transactional catalogs, do not publish version-hint.text until after the catalog update succeeds, and on catalog failure remove the just-written metadata file as well.
  • [src/Storages/ObjectStorage/DataLakes/Iceberg/AlterDropPartitionExecutor.cpp:91] partitionEquals delegates float comparison to accurateEquals, and accurateEquals(Float64(NaN), Float64(NaN)) is explicitly false in gtest_field_accurate_comparison. On a table partitioned by float/double identity keys, ALTER TABLE ... DROP PARTITION tuple(CAST('nan', 'Float64')) silently takes the "no matching files" path even when the partition exists. Suggested fix: either treat NaN keys as equal when both sides are NaN, or reject NaN partition values up front with a documented NOT_IMPLEMENTED exception.

⚠️ Majors

  • [src/Storages/ObjectStorage/DataLakes/Iceberg/AlterDropPartitionExecutor.cpp:763-777] The new manual manifest-list writer does not populate partitions for replacement manifests. generateManifestList already recomputes that field for manifest-only rewrites specifically so partition-pruning bounds survive. After a partial DROP PARTITION, every rewritten manifest loses manifest-list-level partition summaries, so Spark/Trino partition-filtered planning must open those manifests instead of pruning them from the manifest list. Suggested fix: route this path through generateManifestList, or recompute contains_null / contains_nan / lower / upper bounds from the surviving entries before writing the new manifest-list entry.
  • [docs/en/sql-reference/table-functions/iceberg.md:409] The new DROP PARTITION docs still present the feature as generally supported on Iceberg v2 tables, but the implementation rejects several deliberate runtime cases: touched manifests with equality deletes, partial rewrites that would keep files written under another schema-id, and decimal / UUID / boolean partition columns. Those are part of the current user-visible contract and should be documented here instead of surfacing only as runtime NOT_IMPLEMENTED exceptions.
Final Verdict

Changes still need fixes before approval.

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label May 19, 2026
@Diskein
Diskein force-pushed the dk-iceberg-alter-drop-partition branch from 5057b8a to f60db46 Compare June 3, 2026 12:52
@Diskein
Diskein force-pushed the dk-iceberg-alter-drop-partition branch from 962c8f5 to 8bc8c92 Compare June 4, 2026 11:59
@Diskein
Diskein force-pushed the dk-iceberg-alter-drop-partition branch from 1cfbbf2 to f8864c2 Compare June 15, 2026 15:26
entry.field(Iceberg::f_existing_rows_count) = r.existing_rows_count;
entry.field(Iceberg::f_deleted_rows_count) = 0;

writer.write(entry_datum);

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.

writeManifestList is manually emitting the replacement manifest-list entries, but unlike generateManifestList(..., existing_entry_counts, entry_partition_summaries) it never populates partitions. Those summaries are optional for validity, but they are the only manifest-list-level pruning metadata, so every partial DROP PARTITION strips partition bounds from the rewritten manifests.

That means Spark/Trino can still read the table, but partition-filtered planning now has to open each rewritten manifest instead of pruning it from the manifest list. Could we either route this path through generateManifestList or recompute partitions from the surviving entries before writer.write(entry_datum)?

@clickhouse-gh

clickhouse-gh Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.20% 86.10% -0.10%
Functions 92.00% 92.00% +0.00%
Branches 78.30% 78.20% -0.10%

Changed lines: Changed C/C++ lines covered: 767/1167 (65.72%) · Uncovered code

Full report · Diff report

@abashkeev abashkeev added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Sep 4, 2026
Diskein added a commit that referenced this pull request Oct 9, 2026
Rewrite affected manifests while preserving their Avro schema and file
metadata. Record removed files as `DELETED` so concurrent Iceberg writers
can detect the drop, and carry unrelated manifests forward unchanged.
Share partition-summary serialization in `IcebergWrites`.

Cover partition transforms, metadata preservation, and concurrent writes
with Trino and Spark. Keep transform round trips small and run the detailed
metadata scenario separately; extract the REST catalog commit barrier.

Validation: normal `ninja` build and 32 passing integration tests.

Related: #105198
@Diskein Diskein closed this Oct 9, 2026
Diskein added a commit that referenced this pull request Oct 22, 2026
Rewrite affected manifests while preserving their Avro schema and file
metadata. Record removed files as `DELETED` so concurrent Iceberg writers
can detect the drop, and carry unrelated manifests forward unchanged.
Share partition-summary serialization in `IcebergWrites`.

Cover partition transforms, metadata preservation, and concurrent writes
with Trino and Spark. Keep transform round trips small and run the detailed
metadata scenario separately; extract the REST catalog commit barrier.

Validation: normal `ninja` build and 32 passing integration tests.

Related: #105198
Diskein added a commit that referenced this pull request Nov 3, 2026
Rewrite affected manifests while preserving their Avro schema and file
metadata. Record removed files as `DELETED` so concurrent Iceberg writers
can detect the drop, and carry unrelated manifests forward unchanged.
Share partition-summary serialization in `IcebergWrites`.

Cover partition transforms, metadata preservation, and concurrent writes
with Trino and Spark. Keep transform round trips small and run the detailed
metadata scenario separately; extract the REST catalog commit barrier.

Validation: normal `ninja` build and 32 passing integration tests.

Related: #105198
Diskein added a commit that referenced this pull request Nov 4, 2026
Rewrite affected manifests while preserving their Avro schema and file
metadata. Record removed files as `DELETED` so concurrent Iceberg writers
can detect the drop, and carry unrelated manifests forward unchanged.
Share partition-summary serialization in `IcebergWrites`.

Cover partition transforms, metadata preservation, and concurrent writes
with Trino and Spark. Keep transform round trips small and run the detailed
metadata scenario separately; extract the REST catalog commit barrier.

Validation: normal `ninja` build and 32 passing integration tests.

Related: #105198
@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

This branch was successfully deployed

1 active deployment
staging - docs — 5997c122 Deployed Jul 21, 2026 by mintlify[bot]
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-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement ALTER TABLE ... DROP PARTITION ... for Iceberg

3 participants