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


##########
internal/provider/table_schema.go:
##########
@@ -77,9 +87,63 @@ func (s *icebergTableSchema) UnmarshalJSON(b []byte) error {
        s.ID = types.Int64Value(raw.ID)
        s.Fields = raw.Fields
 
+       ids := raw.IdentifierFieldIDs
+       if len(ids) == 0 {
+               // Represent "no identifiers" as an empty list so 
create/read/import
+               // round-trip consistently (null means "omitted from config").
+               s.IdentifierFieldIDs = types.ListValueMust(types.Int64Type, 
[]attr.Value{})
+       } else {
+               elems := make([]attr.Value, len(ids))
+               for i, id := range ids {
+                       elems[i] = types.Int64Value(id)
+               }
+               s.IdentifierFieldIDs = types.ListValueMust(types.Int64Type, 
elems)
+       }
+
        return nil
 }
 
+// int64ListElements returns the int64 elements of a Terraform list, or nil 
when
+// the list is null/unknown (including an unset optional attribute).
+func int64ListElements(list types.List) ([]int64, error) {
+       if list.IsNull() || list.IsUnknown() {
+               return nil, nil
+       }
+       elems := list.Elements()
+       out := make([]int64, 0, len(elems))
+       for _, elem := range elems {
+               v, ok := elem.(types.Int64)
+               if !ok {
+                       return nil, fmt.Errorf("expected int64 list element, 
got %T", elem)
+               }
+               if v.IsNull() || v.IsUnknown() {
+                       continue
+               }
+               out = append(out, v.ValueInt64())
+       }
+
+       return out, nil
+}
+
+// preserveIdentifierFieldIDs copies identifier field IDs from the current 
table
+// schema when the plan omits them (null/unknown). An explicit empty list 
clears
+// identifiers; a non-empty plan list is left unchanged.
+func (s *icebergTableSchema) preserveIdentifierFieldIDs(current 
*iceberg.Schema) {

Review Comment:
   Hi Zeroshade, i have fixed it with `validateIdentifierFields` in my latest 
commit



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