You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by ze...@apache.org on 2026/05/04 16:17:04 UTC
(iceberg-terraform) branch main updated: Schema ID should be set properly (#39)
This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-terraform.git
The following commit(s) were added to refs/heads/main by this push:
new cc12dfd Schema ID should be set properly (#39)
cc12dfd is described below
commit cc12dfd520482840587fa5eeab6abc39c21ad31a
Author: Alex Stephen <13...@users.noreply.github.com>
AuthorDate: Mon May 4 09:16:59 2026 -0700
Schema ID should be set properly (#39)
---
internal/provider/resource_table.go | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
diff --git a/internal/provider/resource_table.go b/internal/provider/resource_table.go
index 8d76751..80171b8 100644
--- a/internal/provider/resource_table.go
+++ b/internal/provider/resource_table.go
@@ -543,7 +543,7 @@ func (r *icebergTableResource) Update(ctx context.Context, req resource.UpdateRe
updates := make([]table.Update, 0)
updates = append(updates, r.calculatePropertyUpdates(ctx, &plan, &state, &resp.Diagnostics)...)
- updates = append(updates, r.calculateSchemaUpdates(ctx, &plan, &state, &resp.Diagnostics)...)
+ updates = append(updates, r.calculateSchemaUpdates(ctx, &plan, &state, tbl, &resp.Diagnostics)...)
updates = append(updates, r.calculatePartitionUpdates(ctx, &plan, tbl, &resp.Diagnostics)...)
updates = append(updates, r.calculateSortOrderUpdates(ctx, &plan, tbl, &resp.Diagnostics)...)
@@ -620,7 +620,7 @@ func (r *icebergTableResource) calculatePropertyUpdates(ctx context.Context, pla
return updates
}
-func (r *icebergTableResource) calculateSchemaUpdates(ctx context.Context, plan, state *icebergTableResourceModel, diags *diag.Diagnostics) []table.Update {
+func (r *icebergTableResource) calculateSchemaUpdates(ctx context.Context, plan, state *icebergTableResourceModel, tbl *table.Table, diags *diag.Diagnostics) []table.Update {
var planSchema, stateSchema icebergTableSchema
d := plan.Schema.As(ctx, &planSchema, basetypes.ObjectAsOptions{})
diags.Append(d...)
@@ -654,9 +654,29 @@ func (r *icebergTableResource) calculateSchemaUpdates(ctx context.Context, plan,
return nil
}
+ // Find the highest existing schema ID to ensure the new one is unique.
+ maxSchemaID := int64(0)
+ for _, s := range tbl.Metadata().Schemas() {
+ if int64(s.ID) > maxSchemaID {
+ maxSchemaID = int64(s.ID)
+ }
+ }
+
+ newSchemaID := maxSchemaID + 1
+ planSchema.ID = types.Int64Value(newSchemaID)
+ planIceberg, err = planSchema.ToIceberg()
+ if err != nil {
+ diags.AddError("failed to convert plan schema with new ID", err.Error())
+
+ return nil
+ }
+
+ // Return two events:
+ // 1. Add the schema with new schema ID.
+ // 2. Set the table schema explicitly to that new ID.
return []table.Update{
table.NewAddSchemaUpdate(planIceberg),
- table.NewSetCurrentSchemaUpdate(-1),
+ table.NewSetCurrentSchemaUpdate(int(newSchemaID)),
}
}