Skip to content

feat(storage): commit a new schema or partition spec to an Iceberg table - #906

Merged
Tr00d merged 4 commits into
masterfrom
feat/storage.analytics.update_table
Nov 26, 2026
Merged

Tr00d merged 4 commits into
masterfrom
feat/storage.analytics.update_table

Conversation

@Tr00d

@Tr00d Tr00d commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Summary

A caller can commit a new current schema, a new default partition spec, or both, to an Iceberg table. They can optionally guard the commit against concurrent changes since the metadata they started from.

Capability: storage.analytics.update_table - Update Iceberg Table. No capability spec exists; the contract comes from the supabase/storage Iceberg commit route and the Iceberg REST CommitTableRequest.

Public API

// IIcebergCatalog
Task<IcebergTableMetadata> UpdateTableAsync(IcebergTable table, IcebergTableChanges changes, CancellationToken cancellationToken = default);

// new, Supabase.Storage.UpdateTable
public sealed record IcebergTableChanges
{
    IcebergSchema? Schema { get; init; }               // made current
    IcebergPartitionSpec? PartitionSpec { get; init; } // made the default
    IcebergTableMetadata? BasedOn { get; init; }       // optional concurrency guard
}
var catalog = storage.Analytics.From("analytics-data");
var events = IcebergNamespace.Of("sales").Table("events");
var current = await catalog.LoadTableAsync(events);
var country = new IcebergField { Id = current.LastColumnId + 1, Name = "country", Type = IcebergPrimitiveType.String, Required = false };
var updated = await catalog.UpdateTableAsync(events, new IcebergTableChanges
{
    Schema = new IcebergSchema { Fields = current.CurrentSchema.Fields.Append(country).ToList() },
    BasedOn = current,
});

Behavior

  • POST {storageUrl}/iceberg/v1/{bucket}/namespaces/{namespace}/tables/{table}, service-role key.
  • The body is {"requirements":[…],"updates":[…]}. Both arrays are always sent, because Storage's route requires them.
  • Updates:
    • Schema becomes add-schema {schema}, then set-current-schema {"schema-id":-1}. In the Iceberg REST spec, -1 means the schema added by the same commit.
    • PartitionSpec becomes add-spec {spec}, then set-default-spec {"spec-id":-1}.
  • Requirements are sent only when BasedOn is set:
    • always assert-table-uuid
    • with a schema change, assert-current-schema-id and assert-last-assigned-field-id
    • with a spec change, assert-default-spec-id and assert-last-assigned-partition-id
  • Without BasedOn, requirements is empty and the last writer wins. Empty changes are sent as is; the catalog judges them.
  • 200 returns the commit response (metadata-location + metadata) as IcebergTableMetadata, with the same mapping as create and load.
  • Failures throw SupabaseStorageException, with the Iceberg error type in Code:
    • 409 CommitFailedException: a requirement failed
    • 400 / 422: the catalog rejected the changes
    • 404 NoSuchTableException, NoSuchNamespaceException or NoSuchCatalog (Reason NotFound)
    • 403 AccessDenied
    • 5xx CommitStateUnknownException
  • Checks before any request:
    • a null table or null changes throws ArgumentNullException
    • a blank table name, or a ./.. table name or namespace, throws ArgumentException

Deviations from supabase-js

  • This is a deliberately minimal typed subset, approved by the maintainer. It covers "make this schema current" and "make this spec the default", with requirements derived from BasedOn. iceberg-js exposes the raw requirements and updates arrays (23 update kinds and 8 requirement kinds). Properties, sort orders, snapshots and locations are out of scope, and more can be added later without breaking callers.
  • No Idempotency-Key header: Storage ignores it.

Tests

Tier Class Pins
Contract UpdateTableApprovalTests exact request bytes: schema change, spec change, each with its BasedOn requirements, empty commit
Contract UpdateTableContractTests POST, path, name escaping, metadata after the commit, the 409 / 400 / 404 / 403 failures, headers read at call time, cancellation, no capture of the caller's context
Unit UpdateTableTests null table, null changes, a name that changes the route, default changes

No E2E: the local stack does not serve the Iceberg routes. Storage registers them only with ICEBERG_ENABLED, which the CLI does not set locally, and table operations proxy to an external Iceberg REST catalog.

Changed-line coverage: 100% (68 lines). Mutation: 37/37 on the changed files (36 killed, 1 timeout on the ConfigureAwait(false) mutant), 0 survivors.

Notes

  • assert-current-schema-id and assert-default-spec-id take the ids from BasedOn.CurrentSchema.SchemaId and BasedOn.DefaultPartitionSpec.SpecId. Metadata the SDK decodes always carries both. Metadata a caller builds by hand without them sends null, and the catalog rejects it.
  • An added schema or spec keeps its SchemaId/SpecId on the wire when the caller set one (for example by copying the current schema with with). The Iceberg REST catalog assigns its own ids, so the value is informational.
  • Failure bodies are pinned from the storage route source and the Iceberg REST spec, not observed on a running service.

@Tr00d
Tr00d marked this pull request as ready for review November 26, 2026 10:26
@Tr00d
Tr00d merged commit 71741f6 into master Nov 26, 2026
7 checks passed
@Tr00d
Tr00d deleted the feat/storage.analytics.update_table branch November 26, 2026 10:36
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.

1 participant