Repository navigation
feat(catalog/glue): support Amazon S3 Tables federated catalogs - #2001
Conversation
Tables in a Glue database federated to Amazon S3 Tables (ConnectionType aws:s3tables) could not be created through the Glue catalog: the service assigns storage itself, so the generic client-side location resolution fails with "no default path set". Detect the federated database and create such tables in two phases, mirroring pyiceberg: create a minimal Glue entry so S3 Tables allocates storage, read the assigned location, write Iceberg metadata to it, then repoint the Glue entry. The allocated entry is rolled back on any later failure. An explicit location is rejected for these tables, and a missing version id is treated as a failed commit. S3 Tables entries also report a service-specific Glue TableType (e.g. "customer"), so getRawTable now accepts any entry marked as Iceberg via the table_type parameter, not only EXTERNAL_TABLE. Adds unit coverage for detection, the two-phase create, location rejection, every rollback path, and the relaxed TableType gate, plus a gated live integration test. Signed-off-by: iremcaginyurtturk <[email protected]>
The final LoadTable ran inside the create's rollback scope, so a transient read failure after a successful commit deleted an already-created table (and reclaimed its storage). Move the reload out of that scope: only allocate/write/commit failures roll back now, which also matches the generic create path. Document that S3 Tables keeps its own Glue TableType on the commit update. Signed-off-by: iremcaginyurtturk <[email protected]>
…e test
Have the successful create path's mocked reload return a service-specific
TableType ("customer"), so the happy path also exercises the relaxed
getRawTable gate rather than only EXTERNAL_TABLE.
Signed-off-by: iremcaginyurtturk <[email protected]>
tanmayrauth
left a comment
There was a problem hiding this comment.
Create/read mechanics and the rollback ordering look right. Two smaller points on the federation probe: it runs on every CreateTable (a redundant GetDatabase for default creates, a brand-new one for explicit-location creates), and for explicit-location creates it newly makes a missing glue:GetDatabase permission or a transient GetDatabase error
…ation - CreateTable now tries the generic path first and only probes for S3 Tables federation when location resolution fails with ErrNoDefaultLocation. This removes the redundant GetDatabase on default creates and avoids a new glue:GetDatabase requirement on explicit-location creates. - Export internal.ErrNoDefaultLocation so the probe matches it via errors.Is instead of the error string. - Scope the relaxed getRawTable TableType gate to entries actually federated to S3 Tables (Table.FederatedTable.ConnectionType == aws:s3tables), so non-federated databases keep their pre-existing behavior. - Tests: prove explicit-location creates skip the probe, prove a non-federated iceberg-param table is still rejected, and update federated mocks.
laskoviymishka
left a comment
There was a problem hiding this comment.
The two-phase create reads well: allocating a minimal entry so S3 Tables assigns storage, writing metadata to the managed location, then repointing the Glue entry, with rollback scoped to createS3TablesTable and LoadTable deliberately left outside it so a transient read can't delete a committed table. That ordering is the right call and the failure-path tests cover a lot of branches.
I'd hold this before merging, though.
Main concern is the explicit-location path. The federation probe only fires on ErrNoDefaultLocation, so a CreateTable with WithLocation against an S3 Tables database skips the probe entirely and quietly writes a plain EXTERNAL_TABLE at the caller's path, outside managed storage and with no federation marker. pyiceberg treats "no explicit location for S3 Tables" as an invariant and rejects it up front. Here TestGlueCreateTableExplicitLocationSkipsFederationProbe actually blesses the bypass as intentional, so we've encoded the divergence. I'd reject an explicit location for an S3 Tables database the way pyiceberg does and flip that test to assert the rejection.
Two other things I'd like to settle in this PR before follow-ups build on it:
- decide what happens to the orphaned metadata file and the stranded minimal Glue entry in the double-failure case (the rollback only deletes the entry, and
DropTablecan't remove it afterward since it has no iceberg table_type param) - tighten
TestGlueCreateTableS3TablesRollbackOnMetadataWriteFailureso it proves the branch it's named for; right nowrequire.Errorpasses for any failure
Once those are addressed I'm happy to take another pass and approve.
… probe - CreateTable rejects an explicit location for a federated S3 Tables database instead of silently creating a table outside managed storage. - isS3TablesDatabase treats AccessDeniedException as not-federated so a caller lacking glue:GetDatabase still reaches the generic create path. - Document the two residual create failures left to the service. - Tighten the metadata-write-failure test to assert the write error. Signed-off-by: iremcaginyurtturk <[email protected]>
When UpdateTable fails after WriteMetadata, the rollback now best-effort deletes the written metadata object before dropping the minimal Glue entry. For S3 Tables the managed location may be unreachable, so the removal error is ignored and reclaiming any remainder is left to the service, as documented. The existing UpdateTable-failure test now asserts the metadata file is gone. Signed-off-by: iremcaginyurtturk <[email protected]>
laskoviymishka
left a comment
There was a problem hiding this comment.
Almost there, and the two round-1 asks I care most about landed. Explicit locations are rejected up front now: isS3TablesDatabase runs before the create when cfg.Location is set, and TestGlueCreateTableS3TablesRejectsExplicitLocation asserts the rejection with CreateTable never called, so the bypass test is gone. The metadata-write rollback test is tight too: unregisteredfs:// plus require.ErrorContains(t, err, "scheme not registered") plus AssertNotCalled on UpdateTable now pins the branch it's named for. Thanks for those.
I still can't approve this pass though. A couple of things:
The orphan case from last round is still open. The comment now says the stranded minimal entry is cleared out of band "matching pyiceberg", but that parity doesn't actually hold: pyiceberg's drop_table has no table_type guard, ours does, so after a double failure the entry is undroppable through DropTable. Details inline, but this is the one I asked to settle in this PR and it isn't settled yet.
The bigger new worry is the UpdateTable repoint. constructTableInput always sends TableType=EXTERNAL_TABLE, and no unit test checks what type we actually send to S3 Tables. If the service rejects EXTERNAL_TABLE on write, every S3 Tables create fails at the commit step and rolls back, which means the feature is quietly broken for everyone and only the gated integration test would catch it. I'd like that assumption either fixed (pass the allocated entry's own type through) or proven with a unit assertion plus an API-contract note.
Two smaller new ones inline: the rollback DeleteTable reuses the cancelled context (rollbackRenameDestination already solved this with context.WithoutCancel), and isS3TablesDatabase can panic if getDatabase returns a nil Database.
Sort out the orphan and the EXTERNAL_TABLE write and I'm happy to take another pass and approve.
…commit - DropTable/getRawTable now accept a minimal federated S3 Tables entry (format=ICEBERG, no table_type), so a double-failure leftover is cleaned up through DropTable, restoring parity with pyiceberg's delete_table. - The UpdateTable repoint preserves the service-assigned TableType instead of forcing EXTERNAL_TABLE, which S3 Tables rejects on write; a unit test now asserts the TableType we send. - The rollback DeleteTable runs on a context detached from a cancelled create (context.WithoutCancel + timeout) and joins errors with errors.Join. - isS3TablesDatabase guards against a nil Database from getDatabase. Signed-off-by: iremcaginyurtturk <[email protected]>
…point Sending the allocated entry's own TableType was untested against S3 Tables and races the service's federation (nil right after CreateTable, "customer" once federated). Live testing confirmed S3 Tables accepts EXTERNAL_TABLE on the repoint, so send it unconditionally and assert it in the unit test. Signed-off-by: iremcaginyurtturk <[email protected]>
…live) Signed-off-by: iremcaginyurtturk <[email protected]>
laskoviymishka
left a comment
There was a problem hiding this comment.
This is looking good to me!
Thanks!
zeroshade
left a comment
There was a problem hiding this comment.
REQUEST_CHANGES on one item. This is a strong patch otherwise, and I agree with the earlier approval on the substance: 587 of the 802 added lines are tests, and they exercise the full two-phase create, explicit-location rejection, malformed Glue responses, metadata and update failures, joined cleanup errors, the detached rollback context, stranded-entry removal, and the scoped TableType relaxation. The catalog ID passes through unchanged in the documented <account>:s3tablescatalog/<bucket> form, table identifiers are validated before the Glue calls, the new error sentinel stays inside catalog/internal, and %w/errors.Join preserve the underlying errors.
The blocking item is a credential-boundary inconsistency within this file; details inline.
The metadata writes in CreateTable, commitS3TablesTable, and CommitTable used a bare context, so the S3 FileIO resolver fell back to LoadDefaultConfig. A catalog built with WithAwsConfig or glue.* static credentials would then call Glue as the configured principal but PUT metadata as the ambient one (or fail despite valid configured credentials). Wrap the context with the catalog's AWS config before each write, matching RegisterTable and convertGlueToIceberg; for commitS3TablesTable this also covers the staged.FS metadata cleanup.
Merging main brought in TestGlueCreateTableAlreadyExists, which does an explicit-location create. CreateTable now consults the database up front to reject federated S3 Tables locations, so the test must mock GetDatabase; a non-federated result lets it take the generic path and assert the AlreadyExists mapping. In real AWS a missing glue:GetDatabase surfaces as AccessDenied, which isS3TablesDatabase already treats as non-federated.
|
@zeroshade Could you please review the pr please🙃 |
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for the ping. The credential-boundary blocker from my 09-21 review is fixed in bc55241: CreateTable (:340), commitS3TablesTable (:456, including the fs.Remove cleanup) and CommitTable (:584) now write metadata under utils.WithAwsConfig(ctx, c.awsCfg).
Still needed before merge:
- the regression test I asked for with that fix (inline at :456);
- the
warehousebypass of the S3 Tables path (inline at :318), whose fix also resolves my openCreateTableOptthread; ErrTableAlreadyExistsmapping on the allocate step (:423) and a decision onRenameTablefor federated tables (:1080);- an updated PR description: the Note still says detection runs a
GetDatabaseon everyCreateTable, and it becomes the squash commit message.
Once these land I will approve; the two-phase create, rollback ordering and federation gating are sound.
- CreateTable now fetches the database once and decides S3 Tables federation for both default and explicit-location creates, reusing the result for namespace properties so staging issues no second GetDatabase. This also catches catalogs with a `warehouse` property, where the previous lazy probe let a federated create write outside the managed storage. - Map AlreadyExistsException from the S3 Tables allocate step to catalog.ErrTableAlreadyExists, matching the other create paths. - Reject RenameTable for federated S3 Tables tables, whose managed storage the copy-then-delete rename cannot safely repoint. - Replace isS3TablesDatabase with lookupDatabase (AccessDenied/NotFound tolerant) and extract namespacePropsFromDatabase. Tests: credential-boundary regression tests (memfs FileIO recording the ctx AWS config) for CreateTable, commitS3TablesTable incl. the fs.Remove cleanup, and CommitTable; warehouse-set federated create; allocate AlreadyExists; rename rejection; catalog-id pinning; and AssertExpectations on the fall-through test.
|
Thanks @zeroshade, addressed in 3d49411:
On parsing the opts once: it's down from 3 to 2. The last one is inside CreateStagedTable, which is shared with the other catalogs, so I left it as is to keep this PR scoped to Glue. |
zeroshade
left a comment
There was a problem hiding this comment.
Everything from my last review is fixed at 94d2762. I've refreshed the PR description to match the current behavior, since it becomes the squash commit message. LGTM. The four nits inline are optional.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Iceberg maintainer. The maintainer
approving this PR has read the findings and signed off. If
something feels off, please reply on the PR and a maintainer
will follow up.More on how Apache Iceberg handles maintainer review:
CONTRIBUTING.md.
| } | ||
|
|
||
| database, tableName, err := identifierToGlueTable(identifier) | ||
| var cfg catalog.CreateTableCfg |
There was a problem hiding this comment.
Nit: cfg is only read in the federated branch, but this loop runs on every create. Non-federated creates now evaluate the options twice, where main evaluated them once. Moving the loop inside the isS3TablesFederatedDatabase branch fixes that, and the glue tests still pass. Your pushback on the S3 Tables path holds: WithLocation(managedLocation) is appended last.
|
|
||
| // ErrNoDefaultLocation is returned when a table has no explicit location and the | ||
| // namespace and catalog define no default warehouse. | ||
| var ErrNoDefaultLocation = errors.New("no default path set, please specify a location when creating a table") |
There was a problem hiding this comment.
Nit: nothing uses ErrNoDefaultLocation since the lazy probe was removed in 3d49411. Reverting this file would keep the PR Glue-only.
| // Fail the repoint so the fs.Remove cleanup runs; the entry is then rolled back. | ||
| mockGlueSvc.On("UpdateTable", mock.Anything, mock.Anything, mock.Anything). | ||
| Return((*glue.UpdateTableOutput)(nil), errors.New("update boom")).Once() | ||
| mockGlueSvc.On("DeleteTable", mock.Anything, mock.Anything, mock.Anything). |
There was a problem hiding this comment.
Nit: the rollback DeleteTable is the only new Glue call whose CatalogId no test checks. Setting catalogId on this test's Catalog and matching it here with mock.MatchedBy would cover it. With that change the test fails if CatalogId is dropped from glue.go:426.
| reloaded, err := ctlg.LoadTable(ctx, ident) | ||
| assert.NoError(err) | ||
| assert.Equal(schema.Fields(), reloaded.Schema().Fields()) | ||
| assert.Equal(tbl.MetadataLocation(), reloaded.MetadataLocation()) |
There was a problem hiding this comment.
Nit: CommitTable can now reach S3 Tables tables, but nothing exercises it against the live service. One SetProperties commit after the reload would cover it:
| assert.Equal(tbl.MetadataLocation(), reloaded.MetadataLocation()) | |
| assert.Equal(tbl.MetadataLocation(), reloaded.MetadataLocation()) | |
| tx := reloaded.NewTransaction() | |
| assert.NoError(tx.SetProperties(iceberg.Properties{"it.commit": "1"})) | |
| committed, err := tx.Commit(ctx) | |
| assert.NoError(err) | |
| assert.NotEqual(reloaded.MetadataLocation(), committed.MetadataLocation()) | |
| assert.Equal("1", committed.Properties()["it.commit"]) |
What
Support creating and reading Iceberg tables in a Glue database federated to Amazon S3 Tables (
FederatedDatabase.ConnectionType == aws:s3tables).Why
CreateTableagainst such a database fails today. S3 Tables assigns storage itself, so the generic client-side location resolution fails withno default path set. Reads fail too, because S3 Tables reports a service-specific GlueTableType(e.g.customer) thatgetRawTablerejected.How
Federation detection.
CreateTablelooks up the database once, before staging. A missing database or anAccessDeniedExceptionis treated as non-federated, so callers withoutglue:GetDatabasekeep the existing behavior. The fetched database is reused to resolve namespace properties. Default-location creates therefore make no extra Glue call, and only explicit-location creates add one round-trip. Default, explicit-location andwarehouse-configured creates are all routed this way.Two-phase create (following pyiceberg's
_create_table_s3tables):format=ICEBERGGlue entry so S3 Tables allocates storage. AnAlreadyExistsExceptionhere maps tocatalog.ErrTableAlreadyExists.UpdateTable.If staging, the metadata write or the repoint fails, the minimal entry is deleted using a detached context with a timeout, so a cancelled create still cleans up. On a failed repoint, the written metadata file is also removed on a best-effort basis. A failure while reloading the table after a successful commit does not roll back. An explicit location is rejected for S3 Tables databases.
Reads.
getRawTableadditionally accepts entries that are S3 Tables federated and marked Iceberg (viatable_type, or the minimalformat=ICEBERGentry). Non-federated tables are still required to beEXTERNAL_TABLE. As a result,DropTablecan remove a minimal entry stranded by a failed create, andCommitTablenow works for S3 Tables tables.Rename.
RenameTablenow rejects S3 Tables tables before writing anything. Copy-then-delete could leave the destination pointing at storage that S3 Tables reclaims when the source is dropped.AWS config for metadata IO (all Glue catalogs).
CreateTable, the S3 Tables commit (including its cleanup) andCommitTablenow write metadata using the catalog's configured AWS config instead of the ambient credential chain.Non-federated create, read and commit behavior is otherwise unchanged.
Testing
warehouse-configured route;catalogIdpass-through;AlreadyExistsmapping;getRawTabletable-type handling;CommitTable.TestGlueCreateTableS3TablesFederatedIntegration.Note
CreateTablenow issues aGetDatabasebefore staging. For default-location creates this replaces the lookup that namespace-property resolution already made. Explicit-location creates gain one Glue round-trip. Ifglue:GetDatabaseis denied, the create proceeds as non-federated, so it is not a new hard permission requirement.