Skip to content

feat(table): add schema evolution support - #596

Merged
zeroshade merged 6 commits into
apache:mainfrom
xixipi-lining:feat_update_schema
Oct 23, 2025
Merged

zeroshade merged 6 commits into
apache:mainfrom
xixipi-lining:feat_update_schema

Conversation

@xixipi-lining

@xixipi-lining xixipi-lining commented Oct 9, 2025 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces initial schema evolution capabilities, allowing users to modify table schemas through a fluent API. This work was originally started by @Shreyas220 in PR #431 , but due to time constraints, I'm continuing the implementation.

Key Features

  • Add Columns: Support for adding primitive types, structs, lists, and maps
  • Delete Columns: Remove fields from the schema
  • Update Columns: Modify field properties including name, type, nullability, and documentation
  • Move Columns: Reorder fields with operations like MoveFirst, MoveBefore, and MoveAfter
  • Rename Columns: Change field names
  • Basic Validation: Type checking and compatibility validation

API Usage

// Create a transaction and update schema
txn := table.NewTransaction()
updateSchema := txn.UpdateSchema(true, false) // caseSensitive=true, allowIncompatibleChanges=false

// Add a new column
updateSchema.AddColumn([]string{"gender"}, iceberg.PrimitiveTypes.String, "User gender", false, nil)

// Add nested column in struct
updateSchema.AddColumn([]string{"address", "country"}, iceberg.PrimitiveTypes.String, "Country code", false, iceberg.StringLiteral("US"))

// Add complex nested structure
updateSchema.AddColumn([]string{"profile"}, &iceberg.StructType{
    FieldList: []iceberg.NestedField{
        {Name: "bio", Type: iceberg.PrimitiveTypes.String, Required: false},
        {Name: "avatar", Type: iceberg.PrimitiveTypes.String, Required: false},
    },
}, "User profile", false, nil)

// Add list type
updateSchema.AddColumn([]string{"tags"}, &iceberg.ListType{
    Element: iceberg.PrimitiveTypes.String,
    ElementRequired: false,
}, "User tags", false, nil)

// Rename a column
updateSchema.RenameColumn([]string{"age"}, "user_age")

// Update column properties
updateSchema.UpdateColumn([]string{"name"}, ColumnUpdate{
    Required: iceberg.Optional[bool]{Valid: true, Val: true},
    Doc: iceberg.Optional[string]{Valid: true, Val: "User's full name"},
})

// Move column to first position
updateSchema.MoveFirst([]string{"id"})

// Move column before another column
updateSchema.MoveBefore([]string{"name"}, []string{"age"})

// Delete a column
updateSchema.DeleteColumn([]string{"old_field"})

// Chain multiple operations
updateSchema.
    AddColumn([]string{"email"}, iceberg.PrimitiveTypes.String, "Email address", true, nil).
    RenameColumn([]string{"phone"}, "phone_number").
    MoveAfter([]string{"email"}, []string{"name"}).
    DeleteColumn([]string{"deprecated_field"})

// Preview changes without committing
newSchema, err := updateSchema.Apply()
if err != nil {
    // Handle validation errors
    return err
}

// Commit the changes
err := updateSchema.Commit()
if err != nil {
    return err
}

// Commit the entire transaction
updatedTable, err := txn.Commit(ctx)

Comment thread table/update_schema.go Resolved

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just needs some docstring comments to explain for users. otherwise looks good!

Comment thread table/update_schema.go Resolved
Comment thread table/transaction.go Resolved
@xixipi-lining

Copy link
Copy Markdown
Contributor Author

Hi @zeroshade, thanks for the feedback! I've added documentation for the UpdateSchema functionality. Please let me know if there's anything else that needs clarification or improvement.

Comment thread table/update_schema.go Resolved
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