zeroshade commented on code in PR #431: URL: https://github.com/apache/iceberg-go/pull/431#discussion_r2190824187
########## table/update_schema.go: ########## @@ -0,0 +1,606 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package table + +import ( + "encoding/json" + "errors" + "fmt" + "strings" + + "github.com/apache/iceberg-go" +) + +type UpdateSchema struct { + txn *Transaction + schema *iceberg.Schema + lastColumnID int + + deletes map[int]struct{} + updates map[int]*iceberg.NestedField + adds map[int][]*iceberg.NestedField Review Comment: do these need to map to pointers instead of just mapping to values? ########## table/update_schema.go: ########## @@ -0,0 +1,606 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package table + +import ( + "encoding/json" + "errors" + "fmt" + "strings" + + "github.com/apache/iceberg-go" +) + +type UpdateSchema struct { + txn *Transaction + schema *iceberg.Schema + lastColumnID int + + deletes map[int]struct{} + updates map[int]*iceberg.NestedField + adds map[int][]*iceberg.NestedField + moves map[int][]moveReq + + allowIncompatibleChanges bool + identifierFields map[string]struct{} + caseSensitive bool +} + +type moveOp string + +const ( + OpFirst moveOp = "first" + OpBefore moveOp = "before" + OpAfter moveOp = "after" +) + +type moveReq struct { + fieldID int + otherFieldID int // 0 when opFirst + op moveOp +} + +func NewUpdateSchema(txn *Transaction, s *iceberg.Schema, lastColumnID int) *UpdateSchema { + return &UpdateSchema{ + txn: txn, + schema: s, + deletes: make(map[int]struct{}), + updates: make(map[int]*iceberg.NestedField), + adds: make(map[int][]*iceberg.NestedField), + moves: make(map[int][]moveReq), + lastColumnID: lastColumnID, + allowIncompatibleChanges: false, + identifierFields: make(map[string]struct{}), + caseSensitive: true, + } +} + +// AllowIncompatibleChanges permits incompatible schema changes. +func (us *UpdateSchema) AllowIncompatibleChanges() *UpdateSchema { + us.allowIncompatibleChanges = true + + return us +} + +// AddColumn adds a new column to the schema. +// usage: +// a is a struct/list/map b is a sub field of a +// +// us.AddColumn([]string{"a","b"}, true, iceberg.StringType{}, "doc", "default") +// us.AddColumn([]string{"a","b"}, true, iceberg.StringType{}, "doc", "default") +func (us *UpdateSchema) AddColumn(path []string, required bool, dataType iceberg.Type, doc string, initialDefault any) (*UpdateSchema, error) { Review Comment: We should either return just `error` or we should return just `*UpdateSchema` and defer all the actual operations to a `Build()` method. There's no reason to return *both* because you don't need the returned `*UpdateSchema` to continue, so we are preventing chaining while not providing anything in return. So we should embrace the Builder pattern entirely, or we should just have the single `error` return. ########## catalog/rest/rest_integration_test.go: ########## @@ -53,6 +53,7 @@ func (s *RestIntegrationSuite) loadCatalog(ctx context.Context) *rest.Catalog { io.S3Region: "us-east-1", io.S3AccessKeyID: "admin", io.S3SecretAccessKey: "password", + io.S3EndpointURL: "http://localhost:9000", Review Comment: do we need this instead relying on the corresponding AWS_ENDPOINT env var? -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org