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 bab8312 fix(table): for add partition spec constant (#382) bab8312 is described below commit bab83126b2bd5f42949b47b8299d1f28dac86e17 Author: Mimi Wang <mimikw...@gmail.com> AuthorDate: Tue Apr 8 21:42:01 2025 -0700 fix(table): for add partition spec constant (#382) `addPartitionSpecAction` should be `add-spec` and not `add-partition-spec`. --------- Co-authored-by: Mimi Wang <mimi.w...@slack-corp.com> --- table/metadata.go | 15 +++++---------- table/metadata_internal_test.go | 14 ++++++++++++++ table/updates.go | 3 ++- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/table/metadata.go b/table/metadata.go index 44986d5..bf53f29 100644 --- a/table/metadata.go +++ b/table/metadata.go @@ -37,11 +37,6 @@ import ( const ( partitionFieldStartID = 1000 supportedTableFormatVersion = 2 - - addPartionSpecAction = "add-partition-spec" - addSchemaAction = "add-schema" - addSnapshotAction = "add-snapshot" - addSortOrderAction = "add-sort-order" ) func generateSnapshotID() int64 { @@ -377,7 +372,7 @@ func (b *MetadataBuilder) SetCurrentSchemaID(currentSchemaID int) (*MetadataBuil return s.ID }) if !slices.ContainsFunc(b.updates, func(u Update) bool { - return u.Action() == addSchemaAction && u.(*addSchemaUpdate).Schema.ID == currentSchemaID + return u.Action() == updateAddSchema && u.(*addSchemaUpdate).Schema.ID == currentSchemaID }) { return nil, errors.New("can't set current schema to last added schema, no schema has been added") } @@ -404,7 +399,7 @@ func (b *MetadataBuilder) SetDefaultSortOrderID(defaultSortOrderID int) (*Metada return s.OrderID }) if !slices.ContainsFunc(b.updates, func(u Update) bool { - return u.Action() == addSortOrderAction && u.(*addSortOrderUpdate).SortOrder.OrderID == defaultSortOrderID + return u.Action() == updateSortOrder && u.(*addSortOrderUpdate).SortOrder.OrderID == defaultSortOrderID }) { return nil, errors.New("can't set default sort order to last added with no added sort orders") } @@ -430,7 +425,7 @@ func (b *MetadataBuilder) SetDefaultSpecID(defaultSpecID int) (*MetadataBuilder, return s.ID() }) if !slices.ContainsFunc(b.updates, func(u Update) bool { - return u.Action() == addPartionSpecAction && u.(*addPartitionSpecUpdate).Spec.ID() == defaultSpecID + return u.Action() == updateSpec && u.(*addPartitionSpecUpdate).Spec.ID() == defaultSpecID }) { return nil, errors.New("can't set default spec to last added with no added partition specs") } @@ -569,7 +564,7 @@ func (b *MetadataBuilder) SetSnapshotRef( } isAddedSnapshot := slices.ContainsFunc(b.updates, func(u Update) bool { - return u.Action() == addSnapshotAction && u.(*addSnapshotUpdate).Snapshot.SnapshotID == snapshotID + return u.Action() == updateSnapshot && u.(*addSnapshotUpdate).Snapshot.SnapshotID == snapshotID }) if isAddedSnapshot { b.lastUpdatedMS = snapshot.TimestampMs @@ -588,7 +583,7 @@ func (b *MetadataBuilder) SetSnapshotRef( } if slices.ContainsFunc(b.updates, func(u Update) bool { - return u.Action() == addSnapshotAction && u.(*addSnapshotUpdate).Snapshot.SnapshotID == snapshotID + return u.Action() == updateSnapshot && u.(*addSnapshotUpdate).Snapshot.SnapshotID == snapshotID }) { b.lastUpdatedMS = snapshot.TimestampMs } diff --git a/table/metadata_internal_test.go b/table/metadata_internal_test.go index 9e33678..dcbfacd 100644 --- a/table/metadata_internal_test.go +++ b/table/metadata_internal_test.go @@ -749,3 +749,17 @@ func TestMetadataV2Serialize(t *testing.T) { "default-sort-order-id":0 }`, string(data)) } + +func TestMetadataBuilderSetDefaultSpecIDLastPartition(t *testing.T) { + builder, err := NewMetadataBuilder() + assert.NoError(t, err) + + partitionSpec := iceberg.NewPartitionSpecID(0) + _, err = builder.AddPartitionSpec(&partitionSpec, false) + assert.NoError(t, err) + + _, err = builder.SetDefaultSpecID(-1) + assert.NoError(t, err) + + assert.Equal(t, 0, builder.defaultSpecID) +} diff --git a/table/updates.go b/table/updates.go index 4225a40..a2e5228 100644 --- a/table/updates.go +++ b/table/updates.go @@ -27,6 +27,7 @@ import ( const ( updateSpec = "add-spec" updateAddSchema = "add-schema" + updateSnapshot = "add-snapshot" updateSortOrder = "add-sort-order" updateAssignUUID = "assign-uuid" updateDefaultSpec = "set-default-spec" @@ -231,7 +232,7 @@ type addSnapshotUpdate struct { // NewAddSnapshotUpdate creates a new update that adds the given snapshot to the table metadata. func NewAddSnapshotUpdate(snapshot *Snapshot) Update { return &addSnapshotUpdate{ - baseUpdate: baseUpdate{ActionName: "add-snapshot"}, + baseUpdate: baseUpdate{ActionName: updateSnapshot}, Snapshot: snapshot, } }