rambleraptor commented on code in PR #158:
URL: 
https://github.com/apache/terraform-provider-iceberg/pull/158#discussion_r4473895385


##########
internal/provider/table_schema.go:
##########
@@ -321,6 +326,71 @@ func validateSchemaEvolution(current, planned 
*iceberg.Schema) error {
        return nil
 }
 
+// validateFieldIDParents rejects a field ID that exists in both schemas under
+// different parents. Iceberg field IDs are identities: moving id 3 from struct
+// "left" to struct "right" (or between list/map containers) silently changes
+// what that ID means. iceberg.IndexParents omits table-root fields, so those
+// are stored as table.TableRootID to catch root↔nested moves too.
+func validateFieldIDParents(current, planned *iceberg.Schema, currentByID, 
plannedByID map[int]iceberg.NestedField) error {
+       currentParents, err := fieldParentIDs(current, currentByID)
+       if err != nil {
+               return err
+       }
+       plannedParents, err := fieldParentIDs(planned, plannedByID)
+       if err != nil {
+               return err
+       }
+
+       ids := make([]int, 0, len(currentParents))
+       for id := range currentParents {
+               ids = append(ids, id)
+       }
+       slices.Sort(ids)
+
+       for _, id := range ids {
+               plannedParent, ok := plannedParents[id]
+               if !ok {
+                       continue
+               }
+               currentParent := currentParents[id]
+               if currentParent == plannedParent {
+                       continue
+               }
+
+               return fmt.Errorf("field %q (id %d): cannot move from parent %s 
to parent %s; field ids cannot change parent",

Review Comment:
   Let's say that you have a.x and b.x and you attempt to swap a and b's names. 
   
   The error message you get is something like field "x" (id 3): cannot move 
from parent "a" (id 1) to parent "a" (id 2), which doesn't really tell you 
anything.



##########
internal/provider/table_schema_test.go:
##########
@@ -186,6 +186,135 @@ func TestValidateSchemaEvolution(t *testing.T) {
        }
 }
 
+func TestValidateFieldIDParents(t *testing.T) {

Review Comment:
   Can we have tests for the following situations:
   - ID left out of config (but still lives on the table)
   - Moving keys inside of a map (same parent, not moving between maps)
   - Some kind of wacky list / map combination with deep nesting
   - 



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