laskoviymishka commented on code in PR #2590:
URL: https://github.com/apache/iceberg-go/pull/2590#discussion_r4577997559


##########
table/update_schema_test.go:
##########
@@ -1316,6 +1316,55 @@ func TestBuildUpdates(t *testing.T) {
        })
 }
 
+func TestBuildUpdatesSelectsAddedSchemaAfterConcurrentRegistration(t 
*testing.T) {
+       for _, tc := range []struct {
+               name        string
+               otherFields []string
+       }{
+               {name: "different schema", otherFields: []string{"a", "b"}},
+               {name: "equivalent schema", otherFields: []string{"a", "c"}},
+       } {
+               t.Run(tc.name, func(t *testing.T) {
+                       a := iceberg.NestedField{ID: 1, Name: "a", Type: 
iceberg.PrimitiveTypes.Int32}
+                       b := iceberg.NestedField{ID: 2, Name: "b", Type: 
iceberg.PrimitiveTypes.Int32}
+                       c := iceberg.NestedField{ID: 3, Name: "c", Type: 
iceberg.PrimitiveTypes.Int32}
+                       base, err := NewMetadata(iceberg.NewSchema(0, a, b, c), 
iceberg.UnpartitionedSpec, UnsortedSortOrder, "", nil)
+                       require.NoError(t, err)
+
+                       tbl := New([]string{"table"}, base, "", nil, nil)
+                       updates, requirements, err := 
tbl.NewTransaction().UpdateSchema(true, false).
+                               DeleteColumn([]string{"b"}).BuildUpdates()
+                       require.NoError(t, err)

Review Comment:
   Could this also assert that the emitted update is `SetCurrentSchema(-1)`? As 
I read it, the `equivalent schema` case gets ID 1 on both sides and passes on 
`main` too, so only `different schema` would catch a revert to `newSchema.ID`.
   
   ```suggestion
                        require.NoError(t, err)
                        require.Len(t, updates, 2)
                        require.Equal(t, -1, 
updates[1].(*setCurrentSchemaUpdate).SchemaID)
   ```



##########
table/update_schema.go:
##########
@@ -1101,7 +1101,7 @@ func (u *UpdateSchema) BuildUpdates() ([]Update, 
[]Requirement, error) {
                        updates = append(
                                updates,
                                NewAddSchemaUpdate(newSchema),
-                               NewSetCurrentSchemaUpdate(newSchema.ID),
+                               NewSetCurrentSchemaUpdate(-1),

Review Comment:
   `-1` already means "not found" for `existingSchemaID` a few lines up. Could 
a one-line comment keep the two meanings apart?
   
   ```suggestion
                                // -1 means the last added schema: the catalog 
may assign newSchema a different ID.
                                NewSetCurrentSchemaUpdate(-1),
   ```



##########
table/update_schema.go:
##########
@@ -1101,7 +1101,7 @@ func (u *UpdateSchema) BuildUpdates() ([]Update, 
[]Requirement, error) {
                        updates = append(
                                updates,
                                NewAddSchemaUpdate(newSchema),
-                               NewSetCurrentSchemaUpdate(newSchema.ID),
+                               NewSetCurrentSchemaUpdate(-1),

Review Comment:
   What happens on a Java REST server when an equivalent schema was added 
concurrently but isn't current? As I read Java's 
[`addSchemaInternal`](https://github.com/apache/iceberg/blob/d1a422988cbde266f10c9e174ddf7c36a08de51a/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1627-L1638),
 reuse nulls `lastAddedSchemaId`, so `SetCurrentSchema(-1)` fails with a 
non-retryable ["Cannot set last added 
schema"](https://github.com/apache/iceberg/blob/d1a422988cbde266f10c9e174ddf7c36a08de51a/core/src/main/java/org/apache/iceberg/TableMetadata.java#L1090-L1095).
 `main` sent `newSchema.ID`, which passes.
   
   Java's 
[`SchemaUpdate`](https://github.com/apache/iceberg/blob/d1a422988cbde266f10c9e174ddf7c36a08de51a/core/src/main/java/org/apache/iceberg/SchemaUpdate.java#L472-L476)
 sends the same pair, and our `equivalent schema` subtest only passes via Go's 
`MetadataBuilder`. Should a comment or the test note that?



-- 
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