leaves12138 commented on code in PR #17:
URL: 
https://github.com/apache/terraform-provider-paimon/pull/17#discussion_r3943438228


##########
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)
+               keyFields := append(stringListFromValue(ctx, 
state.PartitionKeys, &resp.Diagnostics), stringListFromValue(ctx, 
state.PrimaryKeys, &resp.Diagnostics)...)
+               keyFields = append(keyFields, stringListFromValue(ctx, 
plan.PartitionKeys, &resp.Diagnostics)...)

Review Comment:
   **[P2] Defer conversion of partially unknown partition-key lists**
   
   `ModifyPlan` now runs for creates too, but this call converts 
`plan.PartitionKeys` to `[]string` even when the list contains an unknown 
element. For example, this valid configuration fails its initial plan:
   
   ```hcl
   resource "terraform_data" "partition" {
     input = "tenant"
   }
   
   resource "paimon_table" "events" {
     database       = "analytics"
     name           = "events"
     fields         = [{ name = "tenant", type = "STRING" }]
     partition_keys = [terraform_data.partition.output]
   }
   ```
   
   With an existing `analytics` database and the usual provider configuration, 
Terraform reports `Value Conversion Error: Received unknown value, however the 
target type cannot handle unknown values` (`Path: [0]`, `Target Type: string`), 
before it can apply the dependency. I reproduced this using the repository's 
`acceptanceCatalog` and Terraform 1.13.5: the same acceptance test passes at 
base `0646712` and fails at head `8cf932f`.
   
   Please defer key-dependent checks until the individual key elements are 
known, and avoid building replacement-only `keyFields` during creation. The new 
deferred-schema test does not cover this case because its entire `fields` value 
is unknown, so it skips this block. Add an acceptance case with known fields 
and a partially unknown `partition_keys` list.
   



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

Reply via email to