zeroshade commented on code in PR #144:
URL:
https://github.com/apache/terraform-provider-iceberg/pull/144#discussion_r4620749080
##########
internal/provider/resource_table.go:
##########
@@ -497,121 +505,130 @@ func (r *icebergTableResource)
calculateSchemaUpdates(ctx context.Context, plan,
return nil
}
- // Find the highest existing schema ID to ensure the new one is unique.
- maxSchemaID := int64(0)
- for _, s := range tbl.Metadata().Schemas() {
- if int64(s.ID) > maxSchemaID {
- maxSchemaID = int64(s.ID)
- }
+ if tbl.Schema().Equals(planIceberg) {
+ return nil
}
- newSchemaID := maxSchemaID + 1
- planSchema.ID = types.Int64Value(newSchemaID)
- planIceberg, err = planSchema.ToIceberg()
- if err != nil {
- diags.AddError("failed to convert plan schema with new ID",
err.Error())
-
- return nil
+ // Returning to an earlier schema: point back at its existing ID.
+ maxSchemaID := 0
+ for _, existing := range tbl.Metadata().Schemas() {
+ if existing.Equals(planIceberg) {
Review Comment:
Thanks for the quick turnaround. I think moving the lookup above
`validateSchemaEvolution` goes further than my comment intended, and it opens a
hole: reverting is itself an evolution from the *current* schema, so it can
violate the same rules. E.g. schema 0 has `x int`, schema 1 promotes it to
`long`, data gets written as long; reverting to schema 0 is a long→int
narrowing, and it now goes through as a bare `set-current-schema(0)`. Same for
required→optional followed by a revert over rows with nulls. The catalog does
not validate a set-current to an existing schema either.
My concern was only #135's dropped-field-id check. Could we restore
`validateSchemaEvolution` before the lookup, and have #135 place just
`validateNewFieldIDs` after it (or skip it on an exact match)? A
promote-then-revert unit test (int → long → int expecting an error) would pin
this down.
--
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]