Skip to content

Implement Iceberg REST catalog write endpoints - #1618

Closed
dataders wants to merge 10 commits into
unitycatalog:mainfrom
dataders:iceberg-rest-write-endpoints
Closed

dataders wants to merge 10 commits into
unitycatalog:mainfrom
dataders:iceberg-rest-write-endpoints

Conversation

@dataders

@dataders dataders commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Implement Iceberg REST catalog write endpoints

🤖 Heads up: this PR was put together with Claude Fable (AI). A human (@dataders) is driving it and will own the review back-and-forth, but the code + this description were AI-generated. Flagging so reviewers know what they're looking at.

What this does

Adds the write side of the Iceberg REST catalog to OSS Unity Catalog, so spec-compliant clients (PyIceberg, Spark RESTCatalog, the DuckDB iceberg extension, etc.) can actually create and commit to Iceberg tables — not just read UniForm. Covers the write-endpoint part of #3.

Endpoint Gist
POST …/namespaces Create a schema (delegates to SchemaService; single-level only, like today).
POST …/tables Create a native Iceberg table: build initial TableMetadata, write 00000-*.metadata.json via FileIO, register in UC as EXTERNAL with a new ICEBERG format. stage-create supported and stateless (mirrors Iceberg's CatalogHandlers).
POST …/tables/{table} Commit: check UpdateRequirements, apply MetadataUpdates, write the next metadata.json, then CAS the stored location under a row lock. Lost race → 409. assert-create commits materialize a staged create atomically.
DELETE …/tables/{table} Drop a REST-created table. Returns 200 not 204 (Armeria stalls body-less 204s on HTTP/1.1; clients accept 200).

New endpoints are advertised in GET /v1/config so clients that do capability detection (DuckDB) light up automatically.

A few supporting bits:

  • Server-assigned locations: clients that don't send a location (DuckDB) get a MANAGED table at <managed-root>/tables/<uuid>, resolved like managed Delta staging. Explicit location → EXTERNAL.
  • UniForm stays read-only: only ICEBERG-format tables accept commits, so the Delta log and Iceberg metadata can't diverge.
  • Privilege-aware credential vending: FileIOFactory/TableConfigService no longer hardcode SELECT (drops the old FIXME); write creds are only vended to native Iceberg tables, and all routes still authorize as metastore owner.
  • UC-visible schema: Iceberg schemas convert to UC ColumnInfos via a new IcebergSchemaConverter, so tables show up in the UC API/UI. The metadata file stays source of truth for Iceberg clients.

Not in scope (follow-ups, still under #3)

transactions/commit (multi-table), X-Iceberg-Access-Delegation negotiation, register/rename/namespace-properties/views.

Testing

IcebergRestCatalogTest — 5/5 passing, full server/test suite green locally (286 tests, 0 failures). New coverage: full write lifecycle (create → commit → drop, plus dup/stale-requirement/UniForm-rejection cases) and staged-create-then-commit.

Also ran it against real clients on a local server:

  • PyIceberg 0.11.1: create namespace + table (server-assigned location), two appends, scan, properties, drop.
  • DuckDB 1.5.3 (released extension, no patches): both staged-create (CTAS) and direct-create paths, plus INSERT/DROP.
  • Cross-client: DuckDB inserted into a PyIceberg-created table, PyIceberg read it back, and vice versa.

PR Checklist

  • A description of the changes is added to the description of this PR.
  • Documentation update for the change if required
  • Unit test/Integration test added

claude added 5 commits June 20, 2026 14:48
Adds the core write surface to the Iceberg REST catalog service so Iceberg
clients (PyIceberg, Spark RESTCatalog, DuckDB iceberg extension) can create
and commit to tables, addressing the write-endpoint portion of unitycatalog#3:

- POST /v1/{prefix}/namespaces (createNamespace, delegating to SchemaService)
- POST /v1/{prefix}/namespaces/{ns}/tables (createTable: builds the initial
  TableMetadata, writes the 00000- metadata.json server-side, and registers
  the table in UC as an EXTERNAL table with the new ICEBERG data source
  format; staged creates are rejected with a clear error for now)
- POST /v1/{prefix}/namespaces/{ns}/tables/{table} (updateTable/commit:
  validates UpdateRequirements against the current metadata, applies
  MetadataUpdates, writes the next metadata.json, and linearizes the commit
  with a compare-and-swap on the stored metadata location under a pessimistic
  row lock; losers get a 409 CommitFailedException)
- DELETE /v1/{prefix}/namespaces/{ns}/tables/{table} (dropTable)

The new endpoints are advertised in GET /v1/config so spec-aware clients
discover write support. UniForm-enabled Delta tables remain readable but
explicitly read-only through this API, since their Iceberg metadata is
derived from the Delta log.

Storage credential vending is now privilege-aware: FileIOFactory and
TableConfigService take the requested privileges per call instead of the
previous hardcoded read-only set, and loadTable/createTable/commit responses
vend write-capable credentials for native Iceberg tables (all Iceberg REST
routes currently authorize as metastore owner). SimpleLocalFileIO gains
write/delete support for file:// locations, used by tests.

Iceberg schemas are converted to UC columns (Spark StructField type_json
shape) so REST-created tables are browsable through the UC API and UI.
Iceberg clients like DuckDB do not send a location in createTable and rely
on the catalog to assign one. When the request has no location, assign
<managed-root>/tables/<uuid> (schema's managed location, else the catalog's,
else the storage-root.tables server property - the same resolution used for
managed Delta staging locations) and register the table as MANAGED with the
ICEBERG format, skipping the Delta staging contract. Explicit locations keep
creating EXTERNAL tables as before.
Armeria stalls body-less 204 responses on HTTP/1.1 connections (the JUnit
suite doesn't see this because Armeria's client speaks h2). Iceberg REST
clients accept 200 here - DuckDB explicitly allows both, PyIceberg accepts
any 2xx, and apache/iceberg-rest-fixture also returns 200.
Staged creation (createTable with stage-create=true) is stateless, mirroring
Iceberg's reference CatalogHandlers: the initial TableMetadata is built and
returned without a metadata-location and nothing is registered. The table
materializes when the client commits with an assert-create requirement: the
metadata is rebuilt from the commit's updates against an empty base (picking
the format version out of upgrade-format-version first, like
CatalogHandlers.create), the first metadata file is written, and the table is
registered - so registration and the first snapshot land atomically. A
concurrent create loses the race with a 409 CommitFailedException. The table
is MANAGED when its location sits under the managed-tables area the service
assigns from, EXTERNAL otherwise.

For local file locations the table directory layout is pre-created at stage
time, since clients write data and manifest files before the first commit and
object-store-oriented writers don't create parent directories.

This makes DuckDB's default configuration work end-to-end: CREATE TABLE AS
SELECT stages the create, writes data files, and commits once with
assert-create + the first snapshot.
@dataders
dataders force-pushed the iceberg-rest-write-endpoints branch from 948e5c6 to 078b002 Compare June 20, 2026 14:50
claude added 5 commits June 20, 2026 15:40
Exercises TableRepository#setIcebergMetadataLocation under contention:
N commits fire at once, each asserting the original current-schema-id
and bumping the schema. The commits are mutually exclusive, so exactly
one wins (200) and the rest lose cleanly (409 CommitFailedException) --
whether a loser loses the compare-and-swap race or reads post-winner
state where its requirement no longer holds. Verifies no lost updates
and that the table is left consistent at version 1.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JvXw7csrdND28W6LfTGEBa
The Iceberg REST update path writes the new metadata file before the
compare-and-swap of the stored metadata location. Cleanup was previously
scoped to BaseException, so an unexpected RuntimeException from the swap
would leave the metadata file orphaned. Catch RuntimeException, delete the
file in all cases, and still translate UPDATE_REQUIREMENT_CONFLICT into a
CommitFailedException.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SNg6ZpLZHUeVxuJbQNNJcd
Replace the redundant per-class alias with a static import of
CredentialContext.READ_WRITE, matching how the iceberg package classes
reference the shared constant, and fold the authorization rationale into
the loadTable comment where the read-write credential choice is made.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SNg6ZpLZHUeVxuJbQNNJcd
lockTableForUpdate is now shared by the Delta and Iceberg REST commit
paths, but its javadoc only mentioned updateTableForDelta. Note both
callers. Also fold the metastore-owner authorization rationale into the
loadTable comment where the read/write credential choice is made.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SNg6ZpLZHUeVxuJbQNNJcd
Covers the write-path credential plumbing (the removed SELECT-only
FIXME): FileIOFactory and TableConfigService now request read-only
credentials by default and read/write when the Iceberg REST catalog
asks for them. Two Mockito tests verify the privilege set reaching
StorageCredentialVendor for each, using a GCS location so no cloud
client is constructed.

Also extends MetadataServiceTest with a write/delete round-trip against
the existing Adobe S3Mock, exercising writeTableMetadata and
deleteTableMetadata (previously uncovered) end to end on an S3 FileIO.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01JvXw7csrdND28W6LfTGEBa
@yili-db

yili-db commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Hi @dataders, do you still plan to finish this PR? I see that the work has been picked up by #1696. Are you OK with that?

@dataders

Copy link
Copy Markdown
Contributor Author

closing in favor of #1696

@dataders dataders closed this Jul 30, 2026
yili-db added a commit that referenced this pull request Aug 24, 2026
## Summary

Unity Catalog's Iceberg REST catalog can now create and commit native
Iceberg tables instead of limiting Iceberg clients to read-only Delta
UniForm metadata. Spec-aware clients can discover the write endpoints,
create managed or external tables, perform staged creates, commit new
snapshots with conflict protection, and drop catalog-created tables.

This draft is a current-`main`, DCO-clean continuation of the
implementation developed by @dataders in #1618. The implementation
credit and history are called out here explicitly; the commits were
replayed onto current upstream because the original branch is behind
`main` and its DCO check cannot be repaired by a third-party sign-off.

## Design decisions

- Native `ICEBERG` tables are writable, while Delta UniForm tables
remain read-only so Iceberg metadata cannot diverge from the Delta log.
- Commits write a new metadata file and then compare-and-swap the
catalog's metadata pointer under a row lock. Concurrent losers receive a
conflict instead of silently overwriting another snapshot.
- Location-less creates receive a managed location under Unity Catalog's
configured managed root. Explicit locations remain external.
- Staged creates remain unregistered until the client's `assert-create`
commit materializes the table.
- Storage credentials are vended according to the requested read or
write privileges, and the write routes retain metastore-owner
authorization.

The remaining endpoint families in the broader Iceberg REST
specification—such as multi-table transactions, rename/register,
namespace property updates, and view writes—remain outside this change.

## Validation

- Focused Iceberg, schema conversion, metadata, credential, and
cloud-vendor suites: **24 passed, 0 failed**.
- Full server suite: **313 total, 311 passed, 2 skipped, 0 failed, 0
errors**.
- The two skipped classes are the MySQL and PostgreSQL Delta Commits
Testcontainers suites. The local OrbStack endpoint requires Docker API
1.40+, while this repository's older Testcontainers client advertises
API 1.32. Upstream CI should exercise these suites in its supported
Docker environment.
- `serverShaded/assembly`: **passed**.
- Checkstyle and `git diff --check`: **passed**.
- The DCO rewrite changed commit metadata only; the source tree hash
remained identical before and after the rewrite.

## Known interoperability checks

- Recheck the table `HEAD` endpoint with a real HTTP/1.1 Iceberg client;
the Java integration suite passes, but an earlier local client probe
could stall.
- Lowercase REST boolean values work for `purgeRequested`; mixed-case
values such as `False` remain an optional compatibility improvement.

## Related

Related: #3

Continuation of and implementation credit: #1618 by @dataders.

## Post-deploy monitoring & validation

- **Window/owner:** PR author and maintainers during CI, release
qualification, and the first 24 hours of any deployment enabling the new
endpoints.
- **Exercise:** create a namespace and native Iceberg table, append two
snapshots, force one concurrent stale commit, reload the table, and drop
it through a released Iceberg client.
- **Healthy signals:** create/commit/load/drop return expected 2xx
responses; stale commits return 409; the stored metadata location
advances once per successful commit; data remains readable after server
restart.
- **Watch logs for:** `CommitFailedException`,
`UPDATE_REQUIREMENT_CONFLICT`, `Failed to update Iceberg metadata
location`, credential-vending failures, and metadata read/write
exceptions.
- **Failure/rollback trigger:** unexpected 5xx responses, catalog
pointers referencing missing metadata, unauthorized write credentials,
or lost concurrent updates. Stop advertising the write endpoints and
revert this change while preserving the catalog database and Iceberg
metadata for diagnosis.

## PR checklist

- [x] Description explains the behavior and design boundaries.
- [x] Unit and integration coverage is included.
- [x] Focused and full local server validation completed.
- [ ] Upstream CI validates the Docker-backed database suites.
- [ ] Maintainers confirm whether separate user documentation is
required.

---

[![Compound
Engineering](https://img.shields.io/badge/Built_with-Compound_Engineering-6366f1)](https://github.com/EveryInc/compound-engineering-plugin)

---------

Signed-off-by: Kia Yun <[email protected]>
Signed-off-by: Yi Li <[email protected]>
Co-authored-by: dataders <[email protected]>
Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Yi Li <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants