Add icebergUpdateSchema for schema evolution#31
Merged
Conversation
Expose the existing add-schema / set-current-schema commit logic through a stable public entry point so consumers can add nullable columns (or rename columns, promote types) without recreating the table. - icebergStageUpdateSchema: pure metadata-only stage with CAS requirements (assert-current-schema-id, assert-last-assigned-field-id), validated eagerly via applyUpdates - icebergUpdateSchema: top-level commit through commitWithRetry, works for file and REST catalogs - StagedCommit supertype with optional snapshot for metadata-only commits Fixes #25
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.
Fixes #25
Exposes the existing
add-schema/set-current-schemacommit logic through a stable public entry point, so consumers can add nullable columns (or rename columns, promote types) to an existing table in place — no recreate-and-reload.Changes
icebergStageUpdateSchema({ metadata, schema })(stage.js) — pure, metadata-only stage emittingadd-schema(spec sentinelschema-id: -1) +set-current-schema, guarded byassert-table-uuid,assert-current-schema-id, andassert-last-assigned-field-idCAS requirements. RunsapplyUpdateseagerly so evolution violations (field-id reuse, illegal type promotion, required column without defaults) fail at stage time rather than only at commit / server-side.icebergUpdateSchema({ catalog, ..., schema })(write.js) — top-level commit throughcommitWithRetry; retry-safe since it writes no data files. Works for file and REST catalogs.StagedCommitsupertype (types.d.ts) with optionalsnapshotfor metadata-only commits;StagedUpdateextends it and keepssnapshotrequired for the snapshot-producing stages, so existing callers and tests are unaffected.index.js, documented in the README.API
The caller passes the complete evolved schema with field ids assigned: existing columns keep their ids, new columns use ids above the table's
last-column-id(matches HypAware'smergeFieldIdsFromTable). The new schema's id is assigned at commit time.Acceptance criteria from #25
current-schema-id)null(existing read-path null-fill)nullin the new columnTesting
7 new tests in
test/write/update-schema.test.js: the round-trip above, rename-by-field-id, rejection of incompatible type changes and defaultless required columns, and the staged requirements/updates shape.npx tsc,npm run lint, and all 598 tests pass.