Repository navigation
Cherry pick #126924 to 26.10: Fix issue with the write to Iceberg via the glue catalog - #132494
Merged
robot-ch-test-poll4 merged 40 commits intoNov 21, 2026
Merged
Conversation
… 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.
# Conflicts: # src/Databases/DataLake/GlueCatalog.cpp # src/Databases/DataLake/GlueCatalog.h
`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: #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: #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]>
`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: #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: #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: #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: #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: #126924 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test schema has only field 1, while `DEFAULT_SORT_ORDER` refers to field 2, so pyiceberg rejected `create_table` with `ValueError: Could not find in old schema: 2 ASC NULLS FIRST`. The test does not need a sort order, so use `UNSORTED_SORT_ORDER`. Related: #126924 Co-Authored-By: Claude Opus 5.5 <[email protected]>
With `storage_endpoint = 'http://minio1:9001/shared'` and a table in `s3://warehouse/t/`, the early-access client is built for `http://minio1:9001/shared/warehouse/`, i.e. bucket `shared` with key prefix `warehouse/`. `GlueCatalog::createObjectStorageForEarlyTableAccess` returned only `t/...`, and `S3ObjectStorage::readObject` does not add the prefix, so `metadata.json` was read from `shared/t/...`. Because the Glue schema is now always read from `metadata.json`, this broke every table of such a database, while the table storage itself reads `shared/warehouse/t/...`. Return the key prefix parsed by the S3 configuration and add it to the keys in `loadMetadataObject` and `resolveMetadataPathFromTableLocation`. The latter strips it again from the resolved key, so the returned `s3://` URI stays in the catalog's terms. Review: #126924 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::createObjectStorageForEarlyTableAccess` builds the URL with the database setting `storage_uri_style`, but `StorageObjectStorageConfiguration::initialize` parsed it with `s3_uri_style` of the catalog's global context. For a custom endpoint with `storage_uri_style = 'virtual_hosted'` and the server default `s3_uri_style = 'auto'`, `https://warehouse.minio.example.com/` was parsed as path-style with an empty bucket, so the `metadata.json` read failed. Because the Glue schema is now always read from `metadata.json`, this broke every table of such a database. When `storage_uri_style` is not `auto`, initialize the configuration and the object storage with a context copy in which `s3_uri_style` is set to it. Review: #126924 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::buildUpdatedTableInput` regenerated the Glue columns on a plain commit (`updateMetadata`) only when Glue had none. If Glue held an outdated but non-empty column list, for example after `ALTER TABLE ... ADD COLUMN` by a ClickHouse version without Glue column support, every later `INSERT` kept it, and Athena and other Glue consumers never saw the current columns. Only `ALTER` through `updateSchema` replaced them. Always rebuild the columns from `new_schema` or, for a plain commit, from the current schema of the committed metadata, as Apache Iceberg's `GlueTableOperations` does. `test_insert_repairs_empty_glue_columns` becomes `test_insert_rewrites_glue_columns` and also covers an outdated column list. Related: #126924 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`GlueCatalog::glueColumnsFromIcebergSchema` did not set `Comment`, unlike Apache Iceberg's Glue catalog, which writes the field `doc` there. Now that the columns are rebuilt on every commit, comments shown by Athena and the Glue console would be lost. Set `Comment` from `doc` when it is present. Related: #126924 Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # src/Databases/DataLake/RestCatalog.h
… glue-catalog-write-columns Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e cleanup `GlueCatalog::commitTableUpdate` skipped the base comparison when the current Glue entry had no `metadata_location`, so a paused commit could overwrite a table that replaced the original one. A missing pointer is now a conflict, unless the base was resolved from the location of the same pointerless Iceberg table, as `getTableMetadata` does for such tables. When Glue definitively rejects a commit, the metadata file written by this attempt is now removed (`removeRejectedMetadataFile`) in every caller: inserts, mutations, schema changes, compaction, partition drops and snapshot expiration. Before, the next attempt took the version from the Glue pointer, generated the same file name, found its own abandoned file and failed, leaving the table unwritable. The same-version replacement test now expects the paused insert to be rebuilt on top of the replacement and checks that a later `INSERT` and `ALTER TABLE` succeed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…columns Resolve the conflict in `GlueCatalog::buildUpdatedTableInput`: master only updated a comment in the old `updateMetadata` body, which this PR replaced with `tableLocationFromMetadataPath`.
Glue limits `Column.Comment` to 255 characters and rejects control characters other than tab, so copying a long or multiline Iceberg field `doc` verbatim made `CreateTable` and `UpdateTable` fail, which broke every `INSERT` into an existing table with such a doc. Replace control characters with spaces and truncate to 255 UTF-16 code units on a character boundary; the full `doc` stays in the Iceberg metadata. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Fix issue with the write to Iceberg via the glue catalog
Contributor
|
Dear @melvynator, @alexey-milovidov, @arsenmuk, @asya-ch, this cherry-pick PR has not been updated for 3d0h2m40s. Please resolve the conflicts to backport #126924, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity. |
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]>
Member
|
🕵 Resolved the conflicts by merging
Verification: every changed translation unit and the users of the changed headers pass a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #126924
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job