ShivamSharma43 commented on code in PR #2628:
URL: https://github.com/apache/iceberg-go/pull/2628#discussion_r4657806829
##########
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+`]}`), ¤t))
+
+ meta, err := NewMetadata(¤t,
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:
Added in 713d866: each case has a second subtest that renames the nested
column itself and checks both `WriteDefault` and `InitialDefault`. The existing
subtest is unchanged.
--
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]