lliangyu-lin commented on code in PR #467:
URL: https://github.com/apache/iceberg-go/pull/467#discussion_r2195907682


##########
table/update_spec.go:
##########
@@ -0,0 +1,367 @@
+// 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 (
+       "errors"
+       "fmt"
+
+       "github.com/apache/iceberg-go"
+)
+
+type UpdateSpec struct {
+       txn                   *Transaction
+       nameToField           map[string]iceberg.PartitionField
+       nameToAddedField      map[string]iceberg.PartitionField
+       transformToField      map[transformKey]iceberg.PartitionField
+       transformToAddedField map[transformKey]iceberg.PartitionField
+       renames               map[string]string
+       addedTimeFields       map[int]iceberg.PartitionField
+       caseSensitive         bool
+       adds                  []iceberg.PartitionField
+       deletes               map[int]bool
+       lastAssignedFieldId   int
+}
+
+func NewUpdateSpec(t *Transaction, caseSensitive bool) *UpdateSpec {
+       transformToField := make(map[transformKey]iceberg.PartitionField)
+       nameToField := make(map[string]iceberg.PartitionField)
+       partitionSpec := t.tbl.Metadata().PartitionSpec()
+       for partitionField := range partitionSpec.Fields() {
+               transformToField[transformKey{
+                       SourceId:  partitionField.SourceID,
+                       Transform: partitionField.Transform.String(),
+               }] = partitionField
+               nameToField[partitionField.Name] = partitionField
+       }
+       lastAssignedFieldId := t.tbl.Metadata().LastPartitionSpecID()
+       if lastAssignedFieldId == nil {
+               v := iceberg.PartitionDataIDStart - 1
+               lastAssignedFieldId = &v
+       }
+
+       return &UpdateSpec{
+               txn:                   t,
+               nameToField:           nameToField,
+               nameToAddedField:      make(map[string]iceberg.PartitionField),
+               transformToField:      transformToField,
+               transformToAddedField: 
make(map[transformKey]iceberg.PartitionField),
+               renames:               make(map[string]string),
+               addedTimeFields:       make(map[int]iceberg.PartitionField),
+               caseSensitive:         caseSensitive,
+               adds:                  make([]iceberg.PartitionField, 0),
+               deletes:               make(map[int]bool),
+               lastAssignedFieldId:   *lastAssignedFieldId,
+       }
+}
+
+type transformKey struct {
+       SourceId  int
+       Transform string
+}
+
+func (us *UpdateSpec) AddField(sourceColName string, transform 
iceberg.Transform, partitionFieldName string) (*UpdateSpec, error) {

Review Comment:
   I see. Thanks for the clarifications! 
   I like the builder approach in this case. Will try to update this locally 
and do some testings.



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

Reply via email to