zeroshade commented on code in PR #2714:
URL: https://github.com/apache/iceberg-go/pull/2714#discussion_r4722056555


##########
table/update_schema.go:
##########
@@ -654,9 +673,51 @@ func (u *UpdateSchema) findFieldForMove(name string) (int, 
bool) {
        if ok {
                return field.ID, true
        }
-       id, ok := u.addedNameToID[name]
 
-       return id, ok
+       return u.addedFieldID(name)
+}
+
+// addedFieldID returns the ID of a column added earlier in this update,
+// matching the name with UpdateSchema's case sensitivity. AddColumn rejects
+// names that differ only in case, so at most one matches.
+func (u *UpdateSchema) addedFieldID(name string) (int, bool) {
+       if id, ok := u.addedNameToID[name]; ok {
+               return id, true
+       }
+       for addedName, id := range u.addedNameToID {

Review Comment:
   Nit (non-blocking): in case-sensitive mode this loop can never match after 
the map lookup misses, so it could return early when `u.caseSensitive` is set. 
Alternatively, do what Java does and key `addedNameToID` by the case-normalised 
name when inserting (`caseSensitivityAwareName`), which keeps lookups O(1) and 
removes the scan. Only `findFieldForMove` and this code read the map.



##########
table/update_schema.go:
##########
@@ -654,9 +673,51 @@ func (u *UpdateSchema) findFieldForMove(name string) (int, 
bool) {
        if ok {
                return field.ID, true
        }
-       id, ok := u.addedNameToID[name]
 
-       return id, ok
+       return u.addedFieldID(name)
+}
+
+// addedFieldID returns the ID of a column added earlier in this update,
+// matching the name with UpdateSchema's case sensitivity. AddColumn rejects
+// names that differ only in case, so at most one matches.
+func (u *UpdateSchema) addedFieldID(name string) (int, bool) {
+       if id, ok := u.addedNameToID[name]; ok {
+               return id, true
+       }
+       for addedName, id := range u.addedNameToID {
+               if u.sameName(addedName, name) {
+                       return id, true
+               }
+       }
+
+       return 0, false
+}
+
+// findFieldForUpdate finds a field in the original schema, or falls back to a
+// column added earlier in this update. For an added field it also returns
+// a pointer to its entry in u.adds, so the caller can update it in place.
+// For a field in the original schema the pointer is nil.
+func (u *UpdateSchema) findFieldForUpdate(name string) (iceberg.NestedField, 
*iceberg.NestedField, bool) {

Review Comment:
   Nit (non-blocking): this returns the field twice, as a copy and as a pointer 
into `u.adds`, and the pointer is only safe because nothing appends to `u.adds` 
before the write-back. Today only the comment at L710 protects that. Returning 
just `*iceberg.NestedField` (nil for an existing column), or a parent ID plus 
index, would remove the invariant from the API.



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