Skip to content

Improve iceberg writes for unity catalog - #98162

Merged
scanhex12 merged 21 commits into
ClickHouse:masterfrom
scanhex12:fix_iceberg_writes_unity
Mar 28, 2026
Merged

scanhex12 merged 21 commits into
ClickHouse:masterfrom
scanhex12:fix_iceberg_writes_unity

Conversation

@scanhex12

@scanhex12 scanhex12 commented Feb 27, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Improve iceberg writes for the unity catalog

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Changes affect Iceberg write path generation and REST catalog endpoint construction; mistakes could write data to the wrong location or cause commit retries/failures against transactional catalogs.

Overview
Improves Unity/REST catalog compatibility for Iceberg writes by building REST endpoints using the configured catalog prefix and proper namespace URI encoding.

Updates Iceberg metadata generation and writing to better match Unity Catalog expectations: supports write.data.path to place data files under a configured data directory, records correct metadata vs storage paths for written data files, and normalizes manifest list paths (removing escaped slashes).

Hardens the commit loop by failing the write after exhausting metadata initialization retries instead of silently continuing.

Written by Cursor Bugbot for commit 909f2dab8b211e2af711b3dd957c5ec2d11e75ba. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.4.1.347

@scanhex12 scanhex12 changed the title Improve iceberg writes for the unity catalog Improve iceberg writes for unity catalog Feb 27, 2026
@clickhouse-gh

clickhouse-gh Bot commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c9de070]

Summary: ❌

job_name test_name status info comment
Stateless tests (arm_asan_ubsan, targeted) failure
03758_fix_isssue_87414 FAIL cidb
Upgrade check (amd_release) failure
Changed MergeTree settings are not reflected in the settings changes history (see changed_merge_tree_settings.txt) FAIL cidb
New MergeTree settings are not reflected in settings changes history (see new_merge_tree_settings.txt) FAIL cidb

AI Review

Summary

This PR improves Iceberg write compatibility with Unity/REST catalogs (prefix/namespace encoding, write.data.path, manifest-list normalization, retry behavior). The direction is good, but there are still correctness gaps in write-path consistency and REST endpoint construction, so this should not merge yet.

PR Metadata
  • Changelog category: ✅ Improvement matches the change.
  • Changelog entry: required for this category and present, but too vague for users.
    Suggested replacement: Improved Iceberg REST/Unity Catalog writes: fixed namespace/prefix endpoint handling, honored table property \write.data.path` for data-file naming, and made metadata commit retries fail explicitly when exhausted.`
Missing context
  • ⚠️ No CI logs or test results were provided in the review context.
Findings
  • ❌ Blockers

    • [src/Databases/DataLake/RestCatalog.cpp:1104] dropTable still builds endpoint via fmt::format("{}/namespaces/{}/tables/...", base_url, namespace_name, ...) while create/update paths now use config.prefix and encodeNamespaceForURI. This asymmetric path construction can fail table drops for prefixed catalogs and encoded namespaces.
      • Suggested fix: build dropTable endpoint with the same pattern as create/update (base_url / config.prefix / NAMESPACES_ENDPOINT / encodeNamespaceForURI(namespace_name) / "tables" / table_name).
  • ⚠️ Majors

    • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:668, 917-966] write.data.path is loaded only in constructor. On metadata-conflict retry, metadata is reloaded but filename_generator does not refresh/clear this override. Retries can continue writing to a stale location.

      • Suggested fix: after metadata reload in cleanup(true), re-read metadata.properties["write.data.path"]; apply via setDataLocation or clear override when absent.
    • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:668, src/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp:287, src/Storages/ObjectStorage/DataLakes/Iceberg/Compaction.cpp:123,190] write.data.path support is only wired for IcebergStorageSink (append/insert). Mutations and Compaction still generate data paths from table location, producing inconsistent data-file placement for the same table depending on operation type.

      • Suggested fix: propagate the same write.data.path override into Mutations/Compaction FileNamesGenerator setup, or centralize override loading in one shared initialization path.
  • 💡 Nits

    • [src/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp:843] Typo in variable name: successed_write → succeeded_write.
Tests
  • ⚠️ Add regression coverage for REST catalog dropTable with non-empty prefix and namespace values requiring encoding.
  • ⚠️ Add write-path consistency tests ensuring INSERT, mutation, and compaction all respect write.data.path.
  • ⚠️ Add retry test where metadata reload changes write.data.path; verify subsequent retries use the refreshed value.
ClickHouse Rules
Item Status Notes
Deletion logging ✅
Serialization versioning ✅
Core-area scrutiny ⚠️ Partial write.data.path handling across Iceberg write paths (INSERT vs mutation/compaction).
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ⚠️ Same table can get mixed physical data locations depending on operation path.
SettingsChangesHistory.cpp ➖
PR metadata quality ⚠️ Changelog entry is present but too vague for user-facing changelog quality expectations.
Safe rollout ⚠️ Inconsistent endpoint/path behavior can fail operations in some REST catalog configs.
Compilation time ✅
User-Lens

dropTable can fail in catalog setups where other operations succeed, and users may observe different data-file placement semantics between insert and maintenance operations on the same table. Both are surprising and hard to diagnose from SQL level.

Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions:
    1. Fix dropTable endpoint construction to match create/update (prefix + encoded namespace).
    2. Make write.data.path handling consistent across all Iceberg write paths (INSERT, mutation, compaction).
    3. Refresh write.data.path override when metadata is reloaded in retry path.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Feb 27, 2026
@scanhex12
scanhex12 marked this pull request as draft February 27, 2026 06:51
@divanik divanik self-assigned this Feb 28, 2026
@@ -361,7 +361,7 @@ static constexpr const char * manifest_entry_v1_schema = R"(
},
{
"name": "split_offsets",
"type": ["null", {"type": "array", "items": "long", "element-id": 133}],
"type": ["null", {"type": "array", "items": "int", "element-id": 133}],

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.

split_offsets must stay array<long> per Iceberg manifest spec (field-id 132 / element-id 133). Changing it to int breaks compatibility with readers that deserialize offsets as 64-bit and can truncate large offsets for big files. Please keep this field as long in v1 too.

@@ -556,7 +556,7 @@ static constexpr const char * manifest_entry_v2_schema = R"(
},
{
"name": "equality_ids",
"type": ["null", {"type": "array", "items": "int", "element-id": 136}],
"type": ["null", {"type": "array", "items": "long", "element-id": 136}],

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.

equality_ids should remain array<int> (field IDs are 32-bit in Iceberg). Switching this to long changes the Avro schema and can break compatibility with engines expecting the canonical list<int> type for field-id 135/136. Please revert this item type back to int.

@scanhex12
scanhex12 marked this pull request as ready for review March 12, 2026 09:26
storage_data_path = write_data_path.substr(s3_prefix.size());
}

filename_generator.setDataDir(write_data_path + "data/", storage_data_path + "data/");

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.

write.data.path is already the configured data directory in Iceberg. Appending data/ here writes files under <write.data.path>/data/ (often ending up as .../data/data/...) and diverges from the configured location provider semantics. Please pass write_data_path and storage_data_path directly (with only trailing-slash normalization) to setDataDir.

++i;
}
if (!successed_write)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Write into iceberg was not successful");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong error code for transaction retry failure

Low Severity

ErrorCodes::BAD_ARGUMENTS is used for a transaction retry exhaustion error, which is misleading. This error occurs when initializeMetadata() fails after MAX_TRANSACTION_RETRIES attempts, indicating a transactional write conflict or infrastructure issue—not invalid user arguments. A more appropriate error code (e.g., DATALAKE_DATABASE_ERROR) would better communicate the actual failure cause to users.

Fix in Cursor Fix in Web

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.

I agree, maybe use LOGICAL_ERROR ? wdyt ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, logical error is not good there because we can have problems with net and we will get LOGICAL_ERROR in such case, but we shouldn't. I'll change to DATALAKE_DATABASE_ERROR

++i;
}
if (!successed_write)
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Write into iceberg was not successful");

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.

If all MAX_TRANSACTION_RETRIES attempts return false (metadata conflict path), we throw here but never delete the staged data files. initializeMetadata calls cleanup(true), which intentionally keeps data files for retry, so after the final retry these files are left orphaned. Please add a final cleanup before throwing (e.g. iterate writer_per_partition_key and call writer.clearAllDataFiles).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 3 total unresolved issues (including 2 from previous reviews).

Fix All in Cursor

{
String s3_prefix = bucket.substr(0, bucket.size() - config_path.size());
if (write_data_path.starts_with(s3_prefix))
storage_data_path = write_data_path.substr(s3_prefix.size());

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.

If write.data.path does not start with the current table location prefix (s3_prefix), we keep the full URI in storage_data_path and later pass it to writeObject. That writes data under the current table storage with an object key like s3://..., while metadata points to the external URI, so readers cannot find the file. Please fail fast for this mismatch (throw an exception) instead of silently accepting unsupported cross-prefix writes.

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.

I agree that we should throw exception instead of silently failing

@SmitaRKulkarni SmitaRKulkarni self-assigned this Mar 16, 2026
relative_path_with_metadata.getPath(),
Iceberg::f_added_snapshot_id);
}
/// This only happens when we read data written by a old version of iceberg, which violent the spec of iceberg.

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.

Typo: this should be violates the spec, not violent the spec.

Please fix this wording in both occurrences in this block to keep exception/comments clear.

if (properties->has("write.data.path"))
{
auto write_data_path = properties->getValue<String>("write.data.path");
if (!write_data_path.empty())

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.

Maybe we should throw an exception if its empty, wdyt?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it can be empty and this ok

Comment on lines +560 to +561
/// Why do we need this for version 1? In some version, iceberg-spark has changed the type of field `f_added_snapshot_id`
/// from 'null, long' to 'long'. See https://github.com/apache/iceberg/pull/11626.

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.

Looks like we need to update this comment as its not just version 1 anymore.

@SmitaRKulkarni

Copy link
Copy Markdown
Member

@scanhex12 I think this PR should not be in 'Not for changelog' category. Maybe Improvement? wdyt ?
Rest all LGTM, just couple small comments

@@ -50,6 +50,11 @@ class FileNamesGenerator

void setVersion(Int32 initial_version_) { initial_version = initial_version_; }
void setCompressionMethod(CompressionMethod compression_method_) { compression_method = compression_method_; }
void setDataDir(const String & data_table_dir, const String & data_storage_dir)
{
data_dir = data_table_dir;

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 change introduces a build break: setDataDir assigns to data_dir and storage_data_dir, but these members are not declared in FileNamesGenerator.

The current class only has table_location, use_uuid_in_metadata, compression_method, format_name, and initial_version, so this will fail to compile.

Please either add the missing members (and wire them into generateDataFileName) or remove setDataDir until the member storage is implemented.

@@ -36,7 +36,7 @@ class MultipleFileWriter

const std::vector<Iceberg::IcebergPathFromMetadata> & getDataFiles() const
{
return data_file_names;
return data_file_metadata_names;

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 is another compile-time issue: getDataFiles now returns data_file_metadata_names, but the class member is still named data_file_names.

As written, this is an undefined identifier and will break the build.

Please return data_file_names (or rename the member consistently in both header and implementation).

@scanhex12
scanhex12 force-pushed the fix_iceberg_writes_unity branch from 7f6d7d5 to 97a10f5 Compare March 26, 2026 13:55
@scanhex12 scanhex12 added pr-improvement Pull request with some product improvements and removed pr-not-for-changelog This PR should not be mentioned in the changelog labels Mar 27, 2026
@scanhex12

Copy link
Copy Markdown
Member Author

We need to merge ClickHouse/avro#30 before this PR

add_field_to_datum(Iceberg::f_key_metadata);
if (version == 2)
{
add_field_to_datum(Iceberg::f_added_snapshot_id);

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.

new_entry.field(f_added_snapshot_id) is already normalized above to a long (handling legacy ['null','long'] values). Calling add_field_to_datum(Iceberg::f_added_snapshot_id) here overwrites that normalized value with the raw datum from old_entry.

For legacy manifests produced by old iceberg-spark (where added_snapshot_id is a union), this reintroduces the incompatible union value into the v2 record and can fail serialization.

Please remove this call and keep the already-normalized assignment.

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.

agreed, we can remove this line
add_field_to_datum(Iceberg::f_added_snapshot_id);

@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Mar 27, 2026
{
auto properties = metadata->getObject(Iceberg::f_properties);
if (properties && properties->has("write.data.path"))
filename_generator.setDataLocation(properties->getValue<String>("write.data.path"));

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.

When initializeMetadata retries after a metadata conflict, cleanup(true) reloads the latest metadata and updates schema/partition state, but the write.data.path override is not refreshed. Because filename_generator.setDataLocation is only called in the constructor, retries can keep writing data files to a stale location if table properties changed concurrently.

Please reapply write.data.path (or clear it when absent) after reloading metadata in the retry path, so file generation stays consistent with the latest table properties.

@SmitaRKulkarni SmitaRKulkarni left a comment

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.

Rest all LGTM

{
auto properties = metadata->getObject(Iceberg::f_properties);
if (properties && properties->has("write.data.path"))
filename_generator.setDataLocation(properties->getValue<String>("write.data.path"));

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.

write.data.path handling is currently applied only in IcebergStorageSink (append/insert path), but other write paths still generate data files under table_location/data.

For example, Mutations and Compaction create FileNamesGenerator and call generateDataFileName without reading metadata.properties['write.data.path'], so the same table can end up with mixed data-file locations depending on operation type.

Please propagate the same write.data.path override to these code paths as well (or centralize it in FileNamesGenerator initialization), otherwise the fix is partial and behavior remains inconsistent.

@clickhouse-gh

clickhouse-gh Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 84.20% +0.40%
Functions 24.50% 24.40% -0.10%
Branches 76.10% 76.70% +0.60%

Changed lines: 71.18% (121/170) · Uncovered code

Full report · Diff report

@scanhex12
scanhex12 enabled auto-merge March 28, 2026 10:11
@scanhex12
scanhex12 added this pull request to the merge queue Mar 28, 2026
Merged via the queue into ClickHouse:master with commit b1315cb Mar 28, 2026
147 of 149 checks passed
@scanhex12
scanhex12 deleted the fix_iceberg_writes_unity branch March 28, 2026 10:31
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 28, 2026
ebeta-aiven added a commit to aiven/ClickHouse that referenced this pull request Oct 8, 2026
Backport of ClickHouse#98162 (merged
upstream as b1315cb for 26.4) onto v26.3.44.2-lts-aiven.

Unity Catalog and other REST catalogs serve the Iceberg API under a
warehouse prefix, and `config.prefix` already carries it for every read
path. The three write paths built their endpoints with
`fmt::format("{}/namespaces...", base_url)` instead, dropping the prefix
and leaving the namespace unencoded, so `CREATE TABLE` and snapshot
commits hit a path the catalog does not serve. Build them the same way
the read paths do, from `base_url / config.prefix / NAMESPACES_ENDPOINT`
with `encodeNamespaceForURI`.

Alongside that, several things in the write path produced metadata that
other Iceberg readers reject:

- `write.data.path` was ignored, so data files were always written under
  `<table>/data/` even when the table property pointed elsewhere.
- The `manifest_list_v2` Avro schema had no `key_metadata` field (519),
  while the manifest-list writer copies that field from previous
  snapshots.
- `existing_files_count` was taken from the summary's
  `total_data_files`, counting files this manifest does not contain.
- The partition-spec `key` field was written as `int64` where the spec
  requires `int32`.
- `getMaxSequenceNumber` scanned the snapshot array, which understates
  the sequence number once a catalog prunes snapshot history. Read the
  top-level `last-sequence-number` instead.
- Snapshot ids were drawn from `[0, INT32_MAX]`; the spec allows the
  full `int64` range and `0` is not a valid id.
- Rewriting manifest-list entries onto the current schema was done only
  for v1, so v2 entries carrying the old nullable `added_snapshot_id`
  were passed through unchanged.
- `finalizeBuffers` fell out of the retry loop silently when every
  attempt failed, reporting success for a write that never committed.
  `MAX_TRANSACTION_RETRIES` is also raised from 100 to 1000.

Backport deviations from upstream: master reworked FileNamesGenerator
to single metadata-form paths (IcebergPathFromMetadata) and passes a
path resolver into generateManifestList; 26.3 still uses the dual
{path_in_metadata, path_in_storage} Result and the
filename_generator/manifest_lengths signature. The `write.data.path`
override therefore derives the storage path via
convertMetadataPathToStoragePath, which rejects locations outside the
table prefix. The contrib/avro bump in the upstream PR is not included.

Rebase notes from v26.3.32.14-lts to v26.3.44.2-lts-aiven: 26.3.44
hardened the v1 manifest-list rewrite with `validate_field_type` and
`copy_required_field` helpers and an explicit `AVRO_LONG` check on
`added_snapshot_id`. Hoisting the rewrite out of the `version == 1`
branch keeps those helpers and drops the now-redundant `isUnion` /
`unionBranch` handling, since a null union branch already fails the
`AVRO_LONG` check.
ebeta-aiven added a commit to aiven/ClickHouse that referenced this pull request Oct 8, 2026
Backport of ClickHouse#98162 (merged
upstream as b1315cb for 26.4) onto v26.3.44.2-lts-aiven.

Unity Catalog and other REST catalogs serve the Iceberg API under a
warehouse prefix, and `config.prefix` already carries it for every read
path. The three write paths built their endpoints with
`fmt::format("{}/namespaces...", base_url)` instead, dropping the prefix
and leaving the namespace unencoded, so `CREATE TABLE` and snapshot
commits hit a path the catalog does not serve. Build them the same way
the read paths do, from `base_url / config.prefix / NAMESPACES_ENDPOINT`
with `encodeNamespaceForURI`.

Alongside that, several things in the write path produced metadata that
other Iceberg readers reject:

- `write.data.path` was ignored, so data files were always written under
  `<table>/data/` even when the table property pointed elsewhere.
- The `manifest_list_v2` Avro schema had no `key_metadata` field (519),
  while the manifest-list writer copies that field from previous
  snapshots.
- `existing_files_count` was taken from the summary's
  `total_data_files`, counting files this manifest does not contain.
- The partition-spec `key` field was written as `int64` where the spec
  requires `int32`.
- `getMaxSequenceNumber` scanned the snapshot array, which understates
  the sequence number once a catalog prunes snapshot history. Read the
  top-level `last-sequence-number` instead.
- Snapshot ids were drawn from `[0, INT32_MAX]`; the spec allows the
  full `int64` range and `0` is not a valid id.
- Rewriting manifest-list entries onto the current schema was done only
  for v1, so v2 entries carrying the old nullable `added_snapshot_id`
  were passed through unchanged.
- `finalizeBuffers` fell out of the retry loop silently when every
  attempt failed, reporting success for a write that never committed.
  `MAX_TRANSACTION_RETRIES` is also raised from 100 to 1000.

Backport deviations from upstream: master reworked FileNamesGenerator
to single metadata-form paths (IcebergPathFromMetadata) and passes a
path resolver into generateManifestList; 26.3 still uses the dual
{path_in_metadata, path_in_storage} Result and the
filename_generator/manifest_lengths signature. The `write.data.path`
override therefore derives the storage path via
convertMetadataPathToStoragePath, which rejects locations outside the
table prefix. The contrib/avro bump in the upstream PR is not included.

Rebase notes from v26.3.32.14-lts to v26.3.44.2-lts-aiven: 26.3.44
hardened the v1 manifest-list rewrite with `validate_field_type` and
`copy_required_field` helpers and an explicit `AVRO_LONG` check on
`added_snapshot_id`. Hoisting the rewrite out of the `version == 1`
branch keeps those helpers and drops the now-redundant `isUnion` /
`unionBranch` handling, since a null union branch already fails the
`AVRO_LONG` check.
ebeta-aiven added a commit to aiven/ClickHouse that referenced this pull request Oct 14, 2026
Backport of ClickHouse#98162 (merged
upstream as b1315cb for 26.4) onto v26.3.44.2-lts-aiven.

Unity Catalog and other REST catalogs serve the Iceberg API under a
warehouse prefix, and `config.prefix` already carries it for every read
path. The three write paths built their endpoints with
`fmt::format("{}/namespaces...", base_url)` instead, dropping the prefix
and leaving the namespace unencoded, so `CREATE TABLE` and snapshot
commits hit a path the catalog does not serve. Build them the same way
the read paths do, from `base_url / config.prefix / NAMESPACES_ENDPOINT`
with `encodeNamespaceForURI`.

Alongside that, several things in the write path produced metadata that
other Iceberg readers reject:

- `write.data.path` was ignored, so data files were always written under
  `<table>/data/` even when the table property pointed elsewhere.
- The `manifest_list_v2` Avro schema had no `key_metadata` field (519),
  while the manifest-list writer copies that field from previous
  snapshots.
- `existing_files_count` was taken from the summary's
  `total_data_files`, counting files this manifest does not contain.
- The partition-spec `key` field was written as `int64` where the spec
  requires `int32`.
- `getMaxSequenceNumber` scanned the snapshot array, which understates
  the sequence number once a catalog prunes snapshot history. Read the
  top-level `last-sequence-number` instead.
- Snapshot ids were drawn from `[0, INT32_MAX]`; the spec allows the
  full `int64` range and `0` is not a valid id.
- Rewriting manifest-list entries onto the current schema was done only
  for v1, so v2 entries carrying the old nullable `added_snapshot_id`
  were passed through unchanged.
- `finalizeBuffers` fell out of the retry loop silently when every
  attempt failed, reporting success for a write that never committed.
  `MAX_TRANSACTION_RETRIES` is also raised from 100 to 1000.

Backport deviations from upstream: master reworked FileNamesGenerator
to single metadata-form paths (IcebergPathFromMetadata) and passes a
path resolver into generateManifestList; 26.3 still uses the dual
{path_in_metadata, path_in_storage} Result and the
filename_generator/manifest_lengths signature. The `write.data.path`
override therefore derives the storage path via
convertMetadataPathToStoragePath, which rejects locations outside the
table prefix. The contrib/avro bump in the upstream PR is not included.

Rebase notes from v26.3.32.14-lts to v26.3.44.2-lts-aiven: 26.3.44
hardened the v1 manifest-list rewrite with `validate_field_type` and
`copy_required_field` helpers and an explicit `AVRO_LONG` check on
`added_snapshot_id`. Hoisting the rewrite out of the `version == 1`
branch keeps those helpers and drops the now-redundant `isUnion` /
`unionBranch` handling, since a null union branch already fails the
`AVRO_LONG` check.
zvonand added a commit to Altinity/ClickHouse that referenced this pull request Nov 6, 2026
Antalya 26.3 Backport of ClickHouse#98162 - Improve iceberg writes for unity catalog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants