leaves12138 commented on code in PR #17:
URL:
https://github.com/apache/terraform-provider-paimon/pull/17#discussion_r3943852916
##########
internal/provider/resource_table.go:
##########
@@ -85,44 +87,97 @@ func (r *tableResource) Configure(_ context.Context, req
resource.ConfigureReque
}
func (r *tableResource) ModifyPlan(ctx context.Context, req
resource.ModifyPlanRequest, resp *resource.ModifyPlanResponse) {
- if req.State.Raw.IsNull() || req.Plan.Raw.IsNull() {
+ if req.Plan.Raw.IsNull() {
return
}
var config, state, plan tableResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
- resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
+ if !req.State.Raw.IsNull() {
+ resp.Diagnostics.Append(req.State.Get(ctx, &state)...)
+ }
resp.Diagnostics.Append(req.Plan.Get(ctx, &plan)...)
if resp.Diagnostics.HasError() {
return
}
- var configuredFields, stateFields, plannedFields []tableFieldModel
- resp.Diagnostics.Append(config.Fields.ElementsAs(ctx,
&configuredFields, false)...)
- resp.Diagnostics.Append(state.Fields.ElementsAs(ctx, &stateFields,
false)...)
- resp.Diagnostics.Append(plan.Fields.ElementsAs(ctx, &plannedFields,
false)...)
- if resp.Diagnostics.HasError() {
+ stabilizeTableKeys(ctx, config, state, &plan, &resp.Diagnostics)
+ replacementPaths := make([]path.Path, 0)
+ if tableFieldsInspectable(config.Fields) &&
tableFieldsInspectable(plan.Fields) {
+ var configuredFields, stateFields, plannedFields
[]tableFieldModel
+ resp.Diagnostics.Append(config.Fields.ElementsAs(ctx,
&configuredFields, false)...)
+ if !req.State.Raw.IsNull() {
+ resp.Diagnostics.Append(state.Fields.ElementsAs(ctx,
&stateFields, false)...)
+ }
+ resp.Diagnostics.Append(plan.Fields.ElementsAs(ctx,
&plannedFields, false)...)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ if len(configuredFields) != len(plannedFields) {
+ resp.Diagnostics.AddError("Unable to stabilize Paimon
field identities", "The configured and planned field lists have different
lengths. Please report this issue to the provider developers.")
+
+ return
+ }
+
+ stabilizePlannedFieldIdentities(configuredFields, stateFields,
plannedFields)
+ if !req.State.Raw.IsNull() {
+ validateAddedFieldIDs(stateFields, configuredFields,
&resp.Diagnostics)
+ }
+ stabilizeFieldNullability(ctx, configuredFields, stateFields,
plannedFields, plan, state, &resp.Diagnostics)
+ plan.Fields = fieldsValueFromModels(ctx, plannedFields,
&resp.Diagnostics)
+ if resp.Diagnostics.HasError() {
+ return
+ }
+ if !req.State.Raw.IsNull() {
+ keyFields := knownTableKeyNames(state.PartitionKeys,
state.PrimaryKeys, plan.PartitionKeys, plan.PrimaryKeys)
+ if compositeFieldTypesRequireReplace(stateFields,
plannedFields) ||
+ keyFieldTypesRequireReplace(stateFields,
plannedFields, keyFields) ||
+ newNonNullableFieldsRequireReplace(stateFields,
plannedFields) {
+ replacementPaths = append(replacementPaths,
path.Root("fields"))
+ }
+ }
+
+ }
+ resp.Diagnostics.Append(resp.Plan.Set(ctx, &plan)...)
+ if req.State.Raw.IsNull() || resp.Diagnostics.HasError() {
return
}
- if len(configuredFields) != len(plannedFields) {
- resp.Diagnostics.AddError("Unable to stabilize Paimon field
identities", "The configured and planned field lists have different lengths.
Please report this issue to the provider developers.")
+ if !plan.PrimaryKeys.IsUnknown() &&
!state.PrimaryKeys.Equal(plan.PrimaryKeys) {
+ replacementPaths = append(replacementPaths,
path.Root("options").AtMapKey("primary-key"))
+ }
+ if !plan.PartitionKeys.IsUnknown() &&
!state.PartitionKeys.Equal(plan.PartitionKeys) {
Review Comment:
Verified fixed at 0ceec99. My original whole-list-unknown acceptance
reproducer now receives the expected destructive-change diagnostic with
allow_replacement = false, and the fixture records only the original table
creation. The new name/database/partition-key guard tests also pass. I
additionally exercised a real fixture apply with allow_replacement explicitly
changed to true: the intended replacement succeeds and the following plan is
clean. Both previous findings are addressed; I have approved the updated head.
--
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]