mattfaltyn commented on code in PR #1988:
URL: https://github.com/apache/iceberg-go/pull/1988#discussion_r3972677489
##########
table/metadata_preflight_test.go:
##########
@@ -85,6 +86,88 @@ func TestParseMetadataBytesAssignsMissingPartitionFieldIDs(t
*testing.T) {
}
}
+func TestParseMetadataBytesNormalizesStaleLastPartitionID(t *testing.T) {
+ data := strings.Replace(ExampleTableMetadataV2,
Review Comment:
> add a require.Contains
Good call—added explicit fixture guards so silent replacement failures go
red.
##########
table/metadata_preflight_test.go:
##########
@@ -85,6 +86,88 @@ func TestParseMetadataBytesAssignsMissingPartitionFieldIDs(t
*testing.T) {
}
}
+func TestParseMetadataBytesNormalizesStaleLastPartitionID(t *testing.T) {
+ data := strings.Replace(ExampleTableMetadataV2,
+ `"last-partition-id": 1000`, `"last-partition-id": 999`, 1)
+
+ parsed, err := ParseMetadataBytes([]byte(data))
+ require.NoError(t, err)
+ require.NotNil(t, parsed.LastPartitionSpecID())
+ assert.Equal(t, 1000, *parsed.LastPartitionSpecID())
+
+ update := NewUpdateSpec(New(nil, parsed, "", nil,
nil).NewTransaction(), false).
+ AddField("x", iceberg.BucketTransform{NumBuckets: 16},
"x_bucket")
+ _, _, err = update.BuildUpdates()
+ require.NoError(t, err)
+ updated, err := update.Apply()
+ require.NoError(t, err)
+ require.Equal(t, 2, updated.NumFields())
+ assert.Equal(t, 1001, updated.Field(1).FieldID)
+}
+
+func TestAssignMissingPartitionFieldIDsPreservesConsistentMetadata(t
*testing.T) {
+ for _, tt := range []struct {
+ name string
+ input string
+ }{
+ {
+ name: "counter below assignment floor with no fields",
+ input:
`{"last-updated-ms":0,"last-partition-id":0,"partition-specs":[{"spec-id":0,"fields":[]}]}`,
+ },
+ {
+ name: "counter above greatest field ID",
+ input:
`{"last-updated-ms":0,"last-partition-id":1001,"partition-specs":[{"spec-id":0,"fields":[{"field-id":1000}]}]}`,
+ },
+ } {
+ t.Run(tt.name, func(t *testing.T) {
+ normalized, err :=
assignMissingPartitionFieldIDs([]byte(tt.input))
+ require.NoError(t, err)
+ assert.Equal(t, tt.input, string(normalized))
+ })
+ }
+}
+
+func TestAssignMissingPartitionFieldIDsNormalizesStaleCounter(t *testing.T) {
Review Comment:
> add a two-spec case and one using the V1 partition-spec key
Thanks—the two-spec history case is covered; the existing V1 missing-ID test
continues to cover its re-marshal path.
--
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]