You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "dttung2905 (via GitHub)" <gi...@apache.org> on 2026/10/18 19:13:22 UTC
[PR] Preserve identifier field ids [terraform-provider-iceberg]
dttung2905 opened a new pull request, #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140
Related to #112 (Preserve identifier field IDs during unrelated schema updates).
Iceberg tables can carry identifier-field-ids for row identity, but the provider’s schema model never represented them. On schema replace, `ToIceberg()` rebuilt the schema without those IDs, so an unrelated change (for example adding an optional field) silently cleared them in the catalog.
This change adds optional/computed `schema.identifier_field_ids` on the table resource and data source, and round-trips them through create, read, and import. When a plan omits the attribute, updates preserve the current table’s identifier IDs; an explicit empty list clears them. Schema-change detection now compares identifier IDs as well as fields, so identity-only updates are committed correctly.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "zeroshade (via GitHub) via issues" <is...@iceberg.apache.org>.
zeroshade commented on code in PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#discussion_r4776107929
##########
internal/provider/table_schema.go:
##########
@@ -79,9 +90,226 @@ func (s *icebergTableSchema) UnmarshalJSON(b []byte) error {
s.ID = types.Int64Value(raw.ID)
s.Fields = raw.Fields
+ // Represent "no identifiers" as an empty set so create/read/import
+ // round-trip consistently (null means "omitted from config").
+ namesByID := fieldNamesByID(raw.Fields, "")
+ elems := make([]attr.Value, 0, len(raw.IdentifierFieldIDs))
+ for _, id := range raw.IdentifierFieldIDs {
+ name, ok := namesByID[id]
+ if !ok {
+ return fmt.Errorf("identifier field id %d not found in schema fields", id)
+ }
+ elems = append(elems, types.StringValue(name))
+ }
+ s.IdentifierFields = types.SetValueMust(types.StringType, elems)
+
return nil
}
+// stringSetElements returns the string elements of a Terraform set, or nil when
+// the set is null/unknown (including an unset optional attribute).
+func stringSetElements(set types.Set) ([]string, error) {
+ if set.IsNull() || set.IsUnknown() {
+ return nil, nil
+ }
+ elems := set.Elements()
+ out := make([]string, 0, len(elems))
+ for _, elem := range elems {
+ v, ok := elem.(types.String)
+ if !ok {
+ return nil, fmt.Errorf("expected string set element, got %T", elem)
+ }
+ if v.IsNull() || v.IsUnknown() {
+ return nil, fmt.Errorf("set contains null or unknown element")
+ }
+ out = append(out, v.ValueString())
+ }
+
+ return out, nil
+}
+
+// fieldNamesByID maps field IDs to dotted paths (e.g. "user.id") for nested structs.
+func fieldNamesByID(fields []icebergTableSchemaField, prefix string) map[int64]string {
+ out := map[int64]string{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[f.ID.ValueInt64()] = name
+ }
+ if f.StructProperties != nil {
+ for id, nested := range fieldNamesByID(f.StructProperties.Fields, name) {
+ out[id] = nested
+ }
+ }
+ }
+
+ return out
+}
+
+// fieldIDsByName maps dotted field paths to IDs.
+func fieldIDsByName(fields []icebergTableSchemaField, prefix string) map[string]int64 {
+ out := map[string]int64{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[name] = f.ID.ValueInt64()
+ }
+ if f.StructProperties != nil {
+ for nested, id := range fieldIDsByName(f.StructProperties.Fields, name) {
+ out[nested] = id
+ }
+ }
+ }
+
+ return out
+}
+
+// resolveIdentifierFieldIDs converts configured identifier field names to sorted
+// Iceberg field IDs. Null/unknown means omitted (nil); an empty set clears.
+func (s icebergTableSchema) resolveIdentifierFieldIDs() ([]int64, error) {
+ names, err := stringSetElements(s.IdentifierFields)
+ if err != nil {
+ return nil, err
+ }
+ if names == nil {
+ return nil, nil
+ }
+ byName := fieldIDsByName(s.Fields, "")
+ ids := make([]int64, 0, len(names))
+ for _, name := range names {
+ id, ok := byName[name]
+ if !ok {
+ return nil, fmt.Errorf("identifier field %q does not exist", name)
Review Comment:
When a preserved identifier's column was dropped, this surfaces as `failed to convert plan schema: identifier field "id" does not exist`. Mentioning `identifier_fields = []` here (as the docs do) would tell users how to proceed.
##########
internal/provider/table_schema.go:
##########
@@ -79,9 +90,226 @@ func (s *icebergTableSchema) UnmarshalJSON(b []byte) error {
s.ID = types.Int64Value(raw.ID)
s.Fields = raw.Fields
+ // Represent "no identifiers" as an empty set so create/read/import
+ // round-trip consistently (null means "omitted from config").
+ namesByID := fieldNamesByID(raw.Fields, "")
+ elems := make([]attr.Value, 0, len(raw.IdentifierFieldIDs))
+ for _, id := range raw.IdentifierFieldIDs {
+ name, ok := namesByID[id]
+ if !ok {
+ return fmt.Errorf("identifier field id %d not found in schema fields", id)
+ }
+ elems = append(elems, types.StringValue(name))
+ }
+ s.IdentifierFields = types.SetValueMust(types.StringType, elems)
+
return nil
}
+// stringSetElements returns the string elements of a Terraform set, or nil when
+// the set is null/unknown (including an unset optional attribute).
+func stringSetElements(set types.Set) ([]string, error) {
+ if set.IsNull() || set.IsUnknown() {
+ return nil, nil
+ }
+ elems := set.Elements()
+ out := make([]string, 0, len(elems))
+ for _, elem := range elems {
+ v, ok := elem.(types.String)
+ if !ok {
+ return nil, fmt.Errorf("expected string set element, got %T", elem)
+ }
+ if v.IsNull() || v.IsUnknown() {
+ return nil, fmt.Errorf("set contains null or unknown element")
+ }
+ out = append(out, v.ValueString())
+ }
+
+ return out, nil
+}
+
+// fieldNamesByID maps field IDs to dotted paths (e.g. "user.id") for nested structs.
+func fieldNamesByID(fields []icebergTableSchemaField, prefix string) map[int64]string {
+ out := map[int64]string{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[f.ID.ValueInt64()] = name
+ }
+ if f.StructProperties != nil {
+ for id, nested := range fieldNamesByID(f.StructProperties.Fields, name) {
+ out[id] = nested
+ }
+ }
+ }
+
+ return out
+}
+
+// fieldIDsByName maps dotted field paths to IDs.
+func fieldIDsByName(fields []icebergTableSchemaField, prefix string) map[string]int64 {
+ out := map[string]int64{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[name] = f.ID.ValueInt64()
+ }
+ if f.StructProperties != nil {
+ for nested, id := range fieldIDsByName(f.StructProperties.Fields, name) {
+ out[nested] = id
+ }
+ }
+ }
+
+ return out
+}
+
+// resolveIdentifierFieldIDs converts configured identifier field names to sorted
+// Iceberg field IDs. Null/unknown means omitted (nil); an empty set clears.
+func (s icebergTableSchema) resolveIdentifierFieldIDs() ([]int64, error) {
+ names, err := stringSetElements(s.IdentifierFields)
+ if err != nil {
+ return nil, err
+ }
+ if names == nil {
+ return nil, nil
+ }
+ byName := fieldIDsByName(s.Fields, "")
+ ids := make([]int64, 0, len(names))
+ for _, name := range names {
+ id, ok := byName[name]
+ if !ok {
+ return nil, fmt.Errorf("identifier field %q does not exist", name)
+ }
+ ids = append(ids, id)
+ }
+ sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
Review Comment:
Nit: `slices.Sort(ids)` — the file already imports `slices`, so `sort` can go.
##########
internal/provider/table_schema.go:
##########
@@ -79,9 +90,226 @@ func (s *icebergTableSchema) UnmarshalJSON(b []byte) error {
s.ID = types.Int64Value(raw.ID)
s.Fields = raw.Fields
+ // Represent "no identifiers" as an empty set so create/read/import
+ // round-trip consistently (null means "omitted from config").
+ namesByID := fieldNamesByID(raw.Fields, "")
+ elems := make([]attr.Value, 0, len(raw.IdentifierFieldIDs))
+ for _, id := range raw.IdentifierFieldIDs {
+ name, ok := namesByID[id]
+ if !ok {
+ return fmt.Errorf("identifier field id %d not found in schema fields", id)
+ }
+ elems = append(elems, types.StringValue(name))
+ }
+ s.IdentifierFields = types.SetValueMust(types.StringType, elems)
+
return nil
}
+// stringSetElements returns the string elements of a Terraform set, or nil when
+// the set is null/unknown (including an unset optional attribute).
+func stringSetElements(set types.Set) ([]string, error) {
+ if set.IsNull() || set.IsUnknown() {
+ return nil, nil
+ }
+ elems := set.Elements()
+ out := make([]string, 0, len(elems))
+ for _, elem := range elems {
+ v, ok := elem.(types.String)
+ if !ok {
+ return nil, fmt.Errorf("expected string set element, got %T", elem)
+ }
+ if v.IsNull() || v.IsUnknown() {
+ return nil, fmt.Errorf("set contains null or unknown element")
+ }
+ out = append(out, v.ValueString())
+ }
+
+ return out, nil
+}
+
+// fieldNamesByID maps field IDs to dotted paths (e.g. "user.id") for nested structs.
+func fieldNamesByID(fields []icebergTableSchemaField, prefix string) map[int64]string {
+ out := map[int64]string{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[f.ID.ValueInt64()] = name
+ }
+ if f.StructProperties != nil {
+ for id, nested := range fieldNamesByID(f.StructProperties.Fields, name) {
+ out[id] = nested
+ }
+ }
+ }
+
+ return out
+}
+
+// fieldIDsByName maps dotted field paths to IDs.
+func fieldIDsByName(fields []icebergTableSchemaField, prefix string) map[string]int64 {
+ out := map[string]int64{}
+ for _, f := range fields {
+ name := f.Name
+ if prefix != "" {
+ name = prefix + "." + f.Name
+ }
+ if !fieldIDUnset(f.ID) {
+ out[name] = f.ID.ValueInt64()
+ }
+ if f.StructProperties != nil {
+ for nested, id := range fieldIDsByName(f.StructProperties.Fields, name) {
+ out[nested] = id
+ }
+ }
+ }
+
+ return out
+}
+
+// resolveIdentifierFieldIDs converts configured identifier field names to sorted
+// Iceberg field IDs. Null/unknown means omitted (nil); an empty set clears.
+func (s icebergTableSchema) resolveIdentifierFieldIDs() ([]int64, error) {
+ names, err := stringSetElements(s.IdentifierFields)
+ if err != nil {
+ return nil, err
+ }
+ if names == nil {
+ return nil, nil
+ }
+ byName := fieldIDsByName(s.Fields, "")
+ ids := make([]int64, 0, len(names))
+ for _, name := range names {
+ id, ok := byName[name]
+ if !ok {
+ return nil, fmt.Errorf("identifier field %q does not exist", name)
+ }
+ ids = append(ids, id)
+ }
+ sort.Slice(ids, func(i, j int) bool { return ids[i] < ids[j] })
+
+ return ids, nil
+}
+
+// preserveIdentifierFields copies identifier fields from the current table when
+// the plan omits them (null/unknown). Current IDs are remapped to names in the
+// plan schema so renames keep identity. Dropped columns keep the current table
+// name so ToIceberg/validateIdentifierFields reject the update instead of
+// silently clearing row identity.
+// An explicit empty set clears identifiers; a non-empty plan set is unchanged.
+func (s *icebergTableSchema) preserveIdentifierFields(current *iceberg.Schema) {
+ if !s.IdentifierFields.IsNull() && !s.IdentifierFields.IsUnknown() {
+ return
+ }
+ if current == nil || len(current.IdentifierFieldIDs) == 0 {
+ s.IdentifierFields = types.SetValueMust(types.StringType, []attr.Value{})
+
+ return
+ }
+ namesByID := fieldNamesByID(s.Fields, "")
+ elems := make([]attr.Value, 0, len(current.IdentifierFieldIDs))
+ for _, id := range current.IdentifierFieldIDs {
+ name, ok := namesByID[int64(id)]
+ if !ok {
+ colName, found := current.FindColumnName(id)
+ if !found {
+ continue
+ }
+ name = colName
+ }
+ elems = append(elems, types.StringValue(name))
+ }
+ s.IdentifierFields = types.SetValueMust(types.StringType, elems)
+}
+
+// validateIdentifierFields enforces Iceberg identifier-field rules against a
+// converted schema: each ID must exist, be a required non-float primitive, and
+// must not nest under a list, map, or optional struct.
+func validateIdentifierFields(schema *iceberg.Schema) error {
+ if schema == nil || len(schema.IdentifierFieldIDs) == 0 {
+ return nil
+ }
+ for _, id := range schema.IdentifierFieldIDs {
+ field, ok := schema.FindFieldByID(id)
+ if !ok {
+ return fmt.Errorf("identifier field id %d does not exist", id)
+ }
+ name, _ := schema.FindColumnName(id)
+ if name == "" {
+ name = field.Name
+ }
+ if !field.Required {
+ return fmt.Errorf("cannot use field %q as an identifier field: not a required field", name)
+ }
+ prim, isPrim := field.Type.(iceberg.PrimitiveType)
+ if !isPrim {
+ return fmt.Errorf("cannot use field %q as an identifier field: not a primitive type field", name)
+ }
+ if prim.Equals(iceberg.PrimitiveTypes.Float32) || prim.Equals(iceberg.PrimitiveTypes.Float64) {
+ return fmt.Errorf("cannot use field %q as an identifier field: must not be float or double", name)
+ }
+ if err := validateIdentifierParentChain(schema, id, name); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
+func validateIdentifierParentChain(schema *iceberg.Schema, id int, name string) error {
+ // Walk ancestors via Iceberg's parent index: every parent must be a required
+ // struct (rejects list/map nesting and optional struct parents).
+ idToParent, err := iceberg.IndexParents(schema)
+ if err != nil {
+ return err
+ }
+ idToField, err := iceberg.IndexByID(schema)
+ if err != nil {
+ return err
+ }
+ parentID, ok := idToParent[id]
+ for ok {
+ parent, found := idToField[parentID]
+ if !found {
+ return fmt.Errorf("cannot use field %q as an identifier field: parent id %d not found", name, parentID)
+ }
+ if _, isStruct := parent.Type.(*iceberg.StructType); !isStruct {
+ return fmt.Errorf("cannot use field %q as an identifier field: must not be nested in %s", name, parent.Type.Type())
+ }
+ if !parent.Required {
+ return fmt.Errorf("cannot use field %q as an identifier field: must not be nested in an optional field %q", name, parent.Name)
+ }
+ parentID, ok = idToParent[parent.ID]
+ }
+
+ return nil
+}
+
+// identifierFieldIDsEqual reports whether two identifier-field-id slices name the
+// same fields, independent of element order.
+func identifierFieldIDsEqual(a, b []int) bool {
+ if len(a) != len(b) {
+ return false
+ }
+ if len(a) == 0 {
+ return true
+ }
+ ac := append([]int(nil), a...)
+ bc := append([]int(nil), b...)
+ sort.Ints(ac)
+ sort.Ints(bc)
Review Comment:
Nit: `slices.Sorted`/`slices.Sort` plus `slices.Equal(ac, bc)` would replace the manual loop below.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "zeroshade (via GitHub) via issues" <is...@iceberg.apache.org>.
zeroshade commented on code in PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#discussion_r4620249895
##########
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:
Nothing validates the identifier ids before commit. Per the spec each identifier field must exist in the schema, be required, be primitive, not be float/double, and not be nested under an optional struct/list/map. In particular this carries the table's current ids forward even when the plan drops that field or makes it optional, so the commit either fails with an opaque catalog error or a lenient catalog stores invalid metadata. Could we reject these with a clear diagnostic, alongside the existing `validateFieldIDs` check?
##########
internal/provider/resource_table.go:
##########
@@ -480,13 +484,14 @@ func (r *icebergTableResource) calculateSchemaUpdates(ctx context.Context, plan,
return nil
}
- // Normalize by comparing the JSON of the fields list only.
- // This ignores the top-level schema-id and any other schema-level metadata
- // while ensuring every field change (name, type, id, etc.) is detected.
+ // Compare fields and identifier-field-ids. Ignore top-level schema-id.
planFieldsJson, _ := json.Marshal(planIceberg.Fields())
stateFieldsJson, _ := json.Marshal(stateIceberg.Fields())
+ planIdentJson, _ := json.Marshal(planIceberg.IdentifierFieldIDs)
Review Comment:
Comparing marshalled JSON is order-sensitive, so `[1,2]` vs `[2,1]` would produce a new schema. Switching the attribute to a set (and comparing as a set) avoids that.
##########
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) {
Review Comment:
Minor: silently skipping null/unknown elements could drop a user's identifier. At apply time these should be resolved, so an error seems safer than `continue`.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "dttung2905 (via GitHub) via issues" <is...@iceberg.apache.org>.
dttung2905 commented on PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#issuecomment-7145592399
@zeroshade thank you for the review. Could you help to review it again?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "rambleraptor (via GitHub) via issues" <is...@iceberg.apache.org>.
rambleraptor commented on code in PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#discussion_r4484511824
##########
internal/provider/table_tfschema.go:
##########
@@ -32,6 +32,12 @@ func tableSchemaResourceAttributes() map[string]rscschema.Attribute {
Optional: true,
Computed: true,
},
+ "identifier_field_ids": rscschema.ListAttribute{
Review Comment:
Shouldn't this be a set?
##########
internal/provider/table_tfschema.go:
##########
@@ -32,6 +32,12 @@ func tableSchemaResourceAttributes() map[string]rscschema.Attribute {
Optional: true,
Computed: true,
},
+ "identifier_field_ids": rscschema.ListAttribute{
Review Comment:
We won't always know the identifier fields IDs ahead of time, which makes this challenging. We will know the field names, so that might have to be the way we do this.
##########
internal/provider/table_tfschema.go:
##########
@@ -32,6 +32,12 @@ func tableSchemaResourceAttributes() map[string]rscschema.Attribute {
Optional: true,
Computed: true,
},
+ "identifier_field_ids": rscschema.ListAttribute{
Review Comment:
This will need to be added to docs as well.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "dttung2905 (via GitHub) via issues" <is...@iceberg.apache.org>.
dttung2905 commented on code in PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#discussion_r4619168852
##########
internal/provider/table_tfschema.go:
##########
@@ -32,6 +32,12 @@ func tableSchemaResourceAttributes() map[string]rscschema.Attribute {
Optional: true,
Computed: true,
},
+ "identifier_field_ids": rscschema.ListAttribute{
Review Comment:
yes you are righ about this , it should be `SetAttribute`
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "dttung2905 (via GitHub) via issues" <is...@iceberg.apache.org>.
dttung2905 commented on PR #140:
URL: https://github.com/apache/terraform-provider-iceberg/pull/140#issuecomment-6988299075
Hi @rambleraptor thanks for the review. I totally missed it. Those seem to be great questions that I will dig up and answer you in the next 1-2 days 🙏
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] Preserve identifier field ids [terraform-provider-iceberg]
Posted by "dttung2905 (via GitHub) via issues" <is...@iceberg.apache.org>.
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org