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


##########
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:
   Thanks alot for the review. I have fixed both of your comments :bow: 



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