xixipi-lining opened a new pull request, #596:
URL: https://github.com/apache/iceberg-go/pull/596

   ### 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 #430, 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
   
   ```go
   // 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)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to