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/02/10 17:56:44 UTC

(iceberg-go) branch main updated: fix(table): set current schema to existing schema ID when reusing schema (#712)

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-go.git


The following commit(s) were added to refs/heads/main by this push:
     new ee1b9f18 fix(table): set current schema to existing schema ID when reusing schema (#712)
ee1b9f18 is described below

commit ee1b9f18d7d7e2025d828e5bf41dfae51aa4b30b
Author: Eren Dursun <er...@gmail.com>
AuthorDate: Tue Feb 10 18:56:39 2026 +0100

    fix(table): set current schema to existing schema ID when reusing schema (#712)
    
    fixes #711
---
 table/update_schema.go      |  2 +-
 table/update_schema_test.go | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/table/update_schema.go b/table/update_schema.go
index 0492f085..dd450328 100644
--- a/table/update_schema.go
+++ b/table/update_schema.go
@@ -638,7 +638,7 @@ func (u *UpdateSchema) BuildUpdates() ([]Update, []Requirement, error) {
 			)
 		} else {
 			updates = append(updates,
-				NewSetCurrentSchemaUpdate(newSchema.ID),
+				NewSetCurrentSchemaUpdate(existingSchemaID),
 			)
 		}
 
diff --git a/table/update_schema_test.go b/table/update_schema_test.go
index 8f35363d..1ee56239 100644
--- a/table/update_schema_test.go
+++ b/table/update_schema_test.go
@@ -879,3 +879,37 @@ func TestErrorHandling(t *testing.T) {
 		assert.Contains(t, err.Error(), "default value type mismatch")
 	})
 }
+
+func TestBuildUpdates(t *testing.T) {
+	t.Run("test BuildUpdates sets correct schema ID when existing schema found", func(t *testing.T) {
+		previousSchema := iceberg.NewSchema(0,
+			iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int32, Required: true, Doc: ""},
+		)
+
+		currentSchema := iceberg.NewSchema(1,
+			iceberg.NestedField{ID: 1, Name: "id", Type: iceberg.PrimitiveTypes.Int32, Required: true, Doc: ""},
+			iceberg.NestedField{ID: 2, Name: "name", Type: iceberg.PrimitiveTypes.String, Required: false, Doc: ""},
+		)
+
+		metadata, _ := NewMetadata(previousSchema, iceberg.UnpartitionedSpec, UnsortedSortOrder, "", nil)
+		metadataBuilder, _ := MetadataBuilderFromBase(metadata, "")
+		_ = metadataBuilder.AddSchema(currentSchema)
+		_ = metadataBuilder.SetCurrentSchemaID(1)
+		metadata, _ = metadataBuilder.Build()
+
+		table := New([]string{"table"}, metadata, "", nil, nil)
+		txn := table.NewTransaction()
+		updateSchema := txn.UpdateSchema(true, false).DeleteColumn([]string{"name"})
+
+		updates, requirements, err := updateSchema.BuildUpdates()
+		assert.NoError(t, err)
+		assert.NotNil(t, requirements)
+		assert.Len(t, requirements, 1)
+		assert.IsType(t, &assertCurrentSchemaId{}, requirements[0])
+		assert.Equal(t, 1, requirements[0].(*assertCurrentSchemaId).CurrentSchemaID)
+		assert.NotNil(t, updates)
+		assert.Len(t, updates, 1)
+		assert.IsType(t, &setCurrentSchemaUpdate{}, updates[0])
+		assert.Equal(t, 0, updates[0].(*setCurrentSchemaUpdate).SchemaID)
+	})
+}