Skip to content

Fix issue with the write to Iceberg via the glue catalog - #126924

Merged
arsenmuk merged 38 commits into
ClickHouse:masterfrom
melvynator:glue-catalog-write-columns
Nov 13, 2026
Merged

arsenmuk merged 38 commits into
ClickHouse:masterfrom
melvynator:glue-catalog-write-columns

Conversation

@melvynator

@melvynator melvynator commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

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

Iceberg tables created or written through DataLakeCatalog with catalog_type = 'glue' now register their columns in the Glue table definition, so they can be queried by Athena and other Glue consumers. Previously the Glue entry had an empty column list and Athena failed with COLUMN_NOT_FOUND: Relation contains no accessible columns.

Documentation entry for user-facing changes

No new settings or syntax.

Details

GlueCatalog::createTable/updateMetadata/updateSchema only set Location, metadata_location and table_type. This PR:

  • adds DataLake::icebergTypeToGlueType, the inverse of the existing getType reader, mapping Iceberg types to Hive type strings as Apache Iceberg's Glue catalog does;
  • fills StorageDescriptor.Columns (with iceberg.field.id/optional/current parameters) on CreateTable and on schema changes;
  • makes UpdateTable read-modify-write so commits preserve existing columns and other attributes instead of replacing the whole definition, and records previous_metadata_location.

Verified against real AWS Glue + Athena: create, insert, repeated inserts, ALTER TABLE ADD COLUMN, nested array/map/struct, decimals and timestamps are all readable from Athena afterwards. Unit tests in src/Databases/DataLake/tests/gtest_glue_schema_columns.cpp.


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

Version info

  • Merged into: 26.11.1.2153-master (included in 26.11 and later)
  • Backported to: 26.10.12.10

… create/commit/alter

Tables created or written through DataLakeCatalog(glue) had an empty column list in Glue,
which made them unreadable by Athena (COLUMN_NOT_FOUND: Relation contains no accessible
columns). Translate the Iceberg schema into Glue columns (Hive type strings plus the
iceberg.field.* parameters, as Apache Iceberg Glue catalog does), preserve the existing
table definition on UpdateTable instead of replacing it, and record
previous_metadata_location on each commit.
@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [aad80eb]

Summary: ✅


AI Review

Summary

PR #126924 populates Glue columns from Iceberg schemas, preserves table attributes during commits, and adds optimistic conflict handling. Reviewed head aad80eb6ae8a6aac6f79f42da2ead4d01d7268d7, the full diff, current code, and every existing discussion reply. The latest direct VersionId conflict fix addresses its prior finding. No new inline findings were identified; three previously dismissed concerns remain below, with their deferrals respected.

The empty-schema output reaches DatabaseDataLake::tryGetTableImpl, where local and cluster storage constructors infer columns; getCreateTableQueryImpl obtains those inferred columns for SHOW CREATE TABLE; table iterators feed inferred storage metadata to system.tables, system.columns, and general table consumers. DROP TABLE also constructs storage, causing the retained concern below. The original catalog pointer is carried through inserts, mutations, schema changes, manifest compaction, partition drops, and snapshot expiration; RestCatalog keeps its own transactional checks and UnityV2Catalog forwards the added arguments.

Missing context / blind spots
  • ⚠️ Current-head integration and unit jobs were PENDING in the underlying Praktika report. The fetch helper displayed green labels for entries with zero test results; those are not passing executions. No local build or test execution was performed. Completed results for test_database_glue and GlueSchemaColumns would close this evidence gap.
Findings

❌ Blockers

  • An uncertain catalog commit can delete committed data. GlueCatalog.cpp:928 [dismissed by author -- https://github.com/Fix issue with the write to Iceberg via the glue catalog #126924#discussion_r4507789654]. If UpdateTable lands, its response is lost, and multiple later commits advance the pointer, this throws despite those commits inheriting our snapshot. IcebergStorageSink::initializeMetadata still calls cleanup(false) on that exception (IcebergWrites.cpp:1866), and its destructor also removes files while uncommitted; mutation, compaction, and partition-drop cleanup have the same risk. The error therefore still permits deletion of referenced files. Explicitly deferred to open issue Iceberg writes delete committed files when the catalog commit outcome is unknown #130495. Fix by propagating an unknown outcome that preserves files through cleanup and destruction, or proving success from metadata history.

  • A pointerless replacement bypasses the base-identity check. GlueCatalog.cpp:911 [dismissed by author -- https://github.com/Fix issue with the write to Iceberg via the glue catalog #126924#discussion_r4507789658]. A write based on a registration with metadata_location is still accepted after another writer publishes newer metadata and removes that parameter while retaining an Iceberg registration at the same location. isSamePointerlessTable compares only the current marker and directory; it records neither original pointer presence nor table identity. The newly fetched VersionId consequently permits overwriting the newer state. Carry the original base identity, or explicitly track this remaining case. The author's linked issue Glue: writes keep failing after metadata_location is replaced by another metadata file of the same version #130496 is closed and describes rejected metadata-file cleanup, which this PR fixes; it does not track this pointerless bypass.

⚠️ Majors

Final Verdict

⚠️ Request changes. At minimum, fix or explicitly track the remaining pointerless identity bypass with an issue that actually describes it, and obtain successful current-head regression results. The accepted deferrals to issues 130495 and 130497 remain recorded above; no dismissed thread was reopened or repeated inline.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 20, 2026
Comment thread src/Databases/DataLake/Common.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
@arsenmuk arsenmuk self-assigned this Oct 20, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing aad80eb6a with master bb6fa8b5d (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

25 object files changed (-567.73 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/Mutations.cpp.o 786.52 KiB 594.25 KiB -192.27 KiB (-24.45%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/ExpireSnapshotsExecute.cpp.o 772.85 KiB 581.29 KiB -191.55 KiB (-24.79%)
src/CMakeFiles/dbms.dir/Storages/ObjectStorage/DataLakes/Iceberg/IcebergWrites.cpp.o 1.08 MiB 917.61 KiB -190.41 KiB (-17.18%)
src/CMakeFiles/dbms.dir/Databases/DataLake/GlueCatalog.cpp.o 1.05 MiB 1020.07 KiB -52.11 KiB (-4.86%)
src/CMakeFiles/dbms.dir/Databases/DataLake/Common.cpp.o 66.16 KiB 112.21 KiB +46.05 KiB (+69.61%)

711 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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.58, programs/clickhouse-keeper ×0.65 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.1 s +5.2 s (+267%)
Compile time of recompiled translation units

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

Job report

@arsenmuk arsenmuk 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.

I find both bot's findings valid.
And I think we should extend tests/integration/test_database_glue/test.py to cover the new functionality and some edge cases addressed by the findings

Comment thread src/Databases/DataLake/Common.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
# Conflicts:
#	src/Databases/DataLake/GlueCatalog.cpp
#	src/Databases/DataLake/GlueCatalog.h
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
arsenmuk and others added 5 commits November 3, 2026 17:34
`createObjectStorageForEarlyTableAccess` used `storage_endpoint` verbatim and
dropped the bucket parsed from the `s3://` location. With an endpoint without
the bucket (e.g. `http://minio1:9001`), `metadata.json` was read from the wrong
bucket, and since the schema is now always read from `metadata.json`,
`SHOW CREATE TABLE`, `SELECT` and `INSERT` failed for every Glue table.

Build the endpoint with `TableMetadata::getLocationWithEndpoint`, the same way
`DatabaseDataLake::getStorageEndpointForTable` does for the table itself.

Related: ClickHouse#126924 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A v1 top-level `schema` may omit `schema-id`. `getCurrentSchema` returned it
anyway, and building the cached ClickHouse schema then threw on the missing
`schema-id`, even when `schemas` had a valid entry for `current-schema-id`.
That made such Glue tables inaccessible, although the regular Iceberg reader
(`IcebergMetadata::parseTableSchema`) handles this layout.

Use the top-level v1 `schema` only when it has `schema-id`, otherwise select
the `schemas` entry, as `IcebergMetadata::parseTableSchema` does.

Related: ClickHouse#126924 (comment)

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

The schema cache built `IcebergSchemaProcessor` with geo parsing always
enabled, so `SHOW CREATE TABLE` could show `Geometry` columns that the storage
itself rejects without `allow_geo_types_in_iceberg`. Use the setting, as
`IcebergMetadata` does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
arsenmuk and others added 6 commits November 5, 2026 08:40
`GlueCatalog::createObjectStorageForEarlyTableAccess` stripped only the
`s3://` prefix, so for `s3a://warehouse/t/...` it took `s3a:` as the bucket
and failed to read the metadata. Because the Glue schema is now always read
from `metadata.json`, this broke `SHOW CREATE TABLE`, `SELECT` and `INSERT`
for every table registered with an `s3a://` location, while the table storage
itself supports this scheme.

Strip any `<scheme>://` prefix, as `TableMetadata::setLocation` does. The
parsing is moved into the static `GlueCatalog::resolveEarlyAccessLocation`
to cover it with a unit test.

Review: ClickHouse#126924 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::createObjectStorageForEarlyTableAccess` added the bucket to
`storage_endpoint` with `S3UriStyle::AUTO`, while the table storage uses the
database setting `storage_uri_style` in
`DatabaseDataLake::getStorageEndpointForTable`. With
`storage_uri_style = 'virtual_hosted'`, the metadata read went to a
path-style URL, which such endpoints reject. Because the Glue schema is now
always read from `metadata.json`, this broke every table of such a database.

Pass `storage_uri_style` to the catalog in `CatalogSettings` and use it for
the early metadata reads.

Review: ClickHouse#126924 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog` is constructed with the global context, so the schema read from
`metadata.json` checked the server default of `allow_geo_types_in_iceberg`
instead of the query settings. A Glue table with a `geometry` or `geography`
column threw during schema discovery even when the query enabled the setting.
The result is also cached by metadata location for all queries, so it must
not depend on the settings of one query.

Parse geo types in the catalog, as the Glue type conversion did before this
PR, and leave the check with the query settings to `IcebergMetadata`.

Review: ClickHouse#126924 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::getCurrentSchema` returned the top-level v1 `schema` when it had
an ID, even if `schemas` and `current-schema-id` referenced a newer schema.
`IcebergMetadata::parseTableSchema` and Apache Iceberg prefer `schemas`
whenever it is present, because writers that evolve the schema may leave
`schema` stale. So `SHOW CREATE TABLE` could show dropped or renamed columns,
and filling an empty Glue column list could publish the obsolete schema.

Use `parseTableSchemaV2Method`, as `IcebergMetadata::parseTableSchema` does,
whenever `schemas` is present, and the top-level `schema` only otherwise.
The unit test asserted the obsolete schema; it now expects the schema
referenced by `current-schema-id`.

Review: ClickHouse#126924 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::updateMetadata` and `GlueCatalog::updateSchema` did a blind
`GetTable` + `UpdateTable`: they never returned `false` on a conflict, and a
commit by another engine (Spark, Trino, pyiceberg) between the base read and
our `UpdateTable` was silently overwritten. An SDK retry of an `UpdateTable`
that had already landed could also move `metadata_location` back and restore
stale columns.

Both now go through `GlueCatalog::commitTableUpdate`, which:
- passes the `VersionId` from `GetTable` to `UpdateTable`, and on
  `ConcurrentModificationException` re-reads the table and retries a bounded
  number of times;
- returns `true` if Glue already points to our file (an earlier attempt landed);
- returns `false` if `metadata_location` no longer has the base version of the
  new file, before any `UpdateTable` was sent;
- after an `UpdateTable` was sent, returns `true` if the newer commit names our
  file as `previous_metadata_location`, and throws otherwise, because the files
  may already be referenced and must not be cleaned up.

Why `false` is safe here: the new `vN.metadata.json` is published before the
catalog call, but a catalog-backed writer takes its base only from the Glue
pointer (`getLatestMetadataFileAndVersionWithCatalog`), derives `N` from its
parsed version, and the `If-None-Match` write lets only one writer publish
`vN`. So while Glue does not point to our file, no committed metadata
references it, and the cleanups of the callers (manifest list, attempt-local
manifests and data files) only remove files of this attempt. Comparing the
parsed version instead of the full path avoids an `ICatalog` signature change
and path normalization (`s3://` vs `s3a://`); external Iceberg writers always
move the pointer to a file with a different version.

`expire_snapshots` threw a `LOGICAL_ERROR` on `false`, which only Glue reaches
there; it now retries, since nothing is deleted before the commit.

The new test pauses an `INSERT` before its commit, moves the Glue pointer to an
Iceberg Java style file, and checks that the `INSERT` is rebuilt on top of it.
moto 5.1.5 ignores `VersionId` and never raises
`ConcurrentModificationException`, so that path is not covered by tests.

Related: ClickHouse#126924

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/Databases/DataLake/GlueCatalog.cpp Resolved
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Nov 12, 2026
@arsenmuk
arsenmuk removed this pull request from the merge queue due to a manual request Nov 12, 2026
@arsenmuk
arsenmuk enabled auto-merge November 13, 2026 01:53
@arsenmuk
arsenmuk added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 218d024 Nov 13, 2026
401 of 402 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 17, 2026
alexey-milovidov added a commit that referenced this pull request Nov 21, 2026
Resolve the conflicts of the backport of #126924 to 26.10:

- `DatabaseDataLake::getCreateTableQueryImpl`: 26.10 has no `getTableSchema` helper, so the columns
  are taken from `table_metadata.getSchema` before the fallback to the table storage.
- `GlueCatalog::resolveMetadataPathFromTableLocation`: 26.10 has no `resolve_context` with
  `iceberg_list_only_v_prefixed_metadata_files`, so `getContext` is kept; only the structured
  binding gets the new `catalog_metadata_location` member.
- `GlueCatalog.cpp` includes: the `CurrentMetrics`/`unit.h` includes are removed together with the
  schema cache, and the `CurrentThread`/`ThreadStatus` includes of master are not needed.
- `RestCatalog.h`: 26.10 has no `createTableAtDefaultLocation`, only the `updateMetadata` signature changes.
- `IcebergMetadata`: `getMetadataLogEntries` and `IcebergGetTableStateMicroseconds` do not exist in 26.10;
  the remaining three-element binding in `getRelevantState` is extended.
- `AlterDropPartitionExecutor`: `getRelevantState` has no `ignore_metadata_pointer_overrides` argument in 26.10.
- `glue_fault_proxy.py` does not exist in 26.10 (the Glue fault proxy was added on master later), so it is
  dropped along with `test_writes_rebuild_after_glue_version_id_conflict`, the only test that needs it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
robot-ch-test-poll4 added a commit that referenced this pull request Nov 21, 2026
Cherry pick #126924 to 26.10: Fix issue with the write to Iceberg via the glue catalog
robot-clickhouse added a commit that referenced this pull request Nov 21, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 21, 2026
@clickhouse-gh clickhouse-gh Bot added comp-datalake-catalogs Data lake catalogs: the DataLakeCatalog database engine and its catalog clients - Iceberg REST, A... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…-commit-state-unknown

Master's ClickHouse#126924 rewrote the Glue commit into a VersionId-guarded loop. The
unknown-outcome handling is re-applied inside it: a proven rejection keeps the
old error and cleanup, and any other UpdateTable failure reads the pointer back
before reporting UNKNOWN_STATUS_OF_TRANSACTION.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 24, 2026
The backport of #126924 brought the `metadata_version` helper, which uses
`re.match`, but the `import re` line is not present in the `26.10` version of
the test. This failed the `ruff` style check (`F821 Undefined name`) and
three tests with `NameError: name 're' is not defined`.

https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=133355&sha=432f8223bf8a95c47aed468832cb6923ef6ecd83&name_0=BackportPR&name_1=Style%20check
#133355

Co-Authored-By: Claude Fable 5.2 <[email protected]>
clickhouse-gh Bot added a commit that referenced this pull request Nov 24, 2026
Backport #126924 to 26.10: Fix issue with the write to Iceberg via the glue catalog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release comp-datalake-catalogs Data lake catalogs: the DataLakeCatalog database engine and its catalog clients - Iceberg REST, A... ignore-unresolved-threads Do not limit CI and block merge on unresolved review threads pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v26.10-must-backport

Projects

None yet

9 participants