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


##########
table/update_schema_test.go:
##########
@@ -2171,6 +2171,63 @@ func TestAddColumnStoresBinaryDefaultAsHex(t *testing.T) 
{
        assert.True(t, applied.Equals(&decoded))
 }
 
+// Struct, list and map columns can have a write default ({} for a struct, a 
JSON
+// array or object otherwise). Those defaults are Go maps and slices, which ==
+// cannot compare, so they must not break evolving any other column.
+func TestUpdateSchemaWithNestedTypeWriteDefault(t *testing.T) {
+       tests := []struct {
+               name         string
+               field        string
+               writeDefault any
+       }{
+               {
+                       name: "struct",
+                       field: 
`{"id":2,"name":"point","required":false,"initial-default":{},"write-default":{},`
 +
+                               
`"type":{"type":"struct","fields":[{"id":3,"name":"x","required":false,"type":"int"}]}}`,
+                       writeDefault: map[string]any{},
+               },
+               {
+                       name: "list",
+                       field: 
`{"id":2,"name":"tags","required":false,"write-default":[],` +
+                               
`"type":{"type":"list","element-id":3,"element":"string","element-required":false}}`,
+                       writeDefault: []any{},
+               },
+               {
+                       name: "map",
+                       field: 
`{"id":2,"name":"attrs","required":false,"write-default":{"keys":[],"values":[]},`
 +
+                               
`"type":{"type":"map","key-id":3,"key":"string","value-id":4,"value":"string","value-required":false}}`,
+                       writeDefault: map[string]any{"keys": []any{}, "values": 
[]any{}},
+               },
+       }
+
+       for _, tt := range tests {
+               t.Run(tt.name, func(t *testing.T) {
+                       var current iceberg.Schema
+                       require.NoError(t, 
json.Unmarshal([]byte(`{"type":"struct","schema-id":0,"fields":[`+
+                               
`{"id":1,"name":"id","required":true,"type":"long"},`+tt.field+`]}`), &current))
+
+                       meta, err := NewMetadata(&current, 
iceberg.UnpartitionedSpec, UnsortedSortOrder, "",
+                               iceberg.Properties{PropertyFormatVersion: "3"})
+                       require.NoError(t, err)
+                       txn := New([]string{"tbl"}, meta, "", nil, 
nil).NewTransaction()
+
+                       require.NoError(t, txn.UpdateSchema(true, false).
+                               AddColumn([]string{"name"}, 
iceberg.PrimitiveTypes.String, "", false, nil).
+                               RenameColumn([]string{"id"}, "row_id").
+                               Commit())
+
+                       applied := txn.meta.CurrentSchema()
+                       _, ok := applied.FindFieldByName("name")
+                       assert.True(t, ok)
+                       _, ok = applied.FindFieldByName("row_id")
+                       assert.True(t, ok)
+                       field, ok := applied.FindFieldByID(2)
+                       require.True(t, ok)
+                       assert.Equal(t, tt.writeDefault, field.WriteDefault)

Review Comment:
   Could we add a subtest that renames the nested column itself and also 
asserts `InitialDefault`? Here field 2 always takes the reuse branch, so the 
[rebuild that copies both 
defaults](https://github.com/apache/iceberg-go/blob/f0f7798250896ff47a1f7689568854c8e8acd40f/table/update_schema.go#L1336-L1346)
 isn't covered. The current case should stay, since renaming field 2 
short-circuits before the `DeepEqual` and wouldn't reproduce the panic.



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