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


##########
internal/provider/table_schema.go:
##########
@@ -44,6 +45,8 @@ type tableFieldModel struct {
        DefaultValue types.String `tfsdk:"default_value"`
 }
 
+const maxPaimonFieldID = 1<<31 - 1

Review Comment:
   This upper bound includes Paimon's reserved system-field ID range. In Paimon 
master, `SpecialFields.SYSTEM_FIELD_ID_START` is `Integer.MAX_VALUE / 2`, and 
IDs at or above that value are treated as system fields (for example, 
`DataEvolutionFileStoreScan` filters them out); several IDs near 
`Integer.MAX_VALUE` are also assigned to built-in fields. Accepting user fields 
up to `2147483647` can therefore create schemas whose columns are later 
mistaken for system columns. Please cap user-assigned IDs below the reserved 
range (and apply the same bound to generated nested IDs), with a boundary test.



##########
internal/provider/table_options.go:
##########
@@ -0,0 +1,172 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package provider
+
+import (
+       "context"
+       "strings"
+
+       "github.com/hashicorp/terraform-plugin-framework/diag"
+       
"github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier"
+       
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
+       "github.com/hashicorp/terraform-plugin-framework/schema/validator"
+       "github.com/hashicorp/terraform-plugin-framework/types"
+)
+
+var immutableTableOptions = map[string]struct{}{
+       "aggregation.remove-record-on-delete":            {},
+       "blob-descriptor-field":                          {},
+       "blob-field":                                     {},
+       "blob-view-field":                                {},
+       "bucket-function.type":                           {},
+       "bucket-key":                                     {},
+       "data-evolution.enabled":                         {},
+       "data-file.path-directory":                       {},
+       "dynamic-bucket.initial-buckets":                 {},
+       "force-lookup":                                   {},
+       "index-file-in-data-file-dir":                    {},
+       "merge-engine":                                   {},
+       "partial-update.remove-record-on-delete":         {},
+       "partial-update.remove-record-on-sequence-group": {},
+       "partition":                                      {},
+       "pk-clustering-override":                         {},
+       "primary-key":                                    {},
+       "primary-key.nullable":                           {},
+       "row-tracking.enabled":                           {},
+       "rowkind.field":                                  {},
+       "sequence.snapshot-ordering":                     {},
+       "type":                                           {},
+}
+
+type reservedTableOptionsValidator struct{}
+
+func (reservedTableOptionsValidator) Description(context.Context) string {
+       return "must configure primary keys and partitions with their 
first-class attributes"
+}
+
+func (reservedTableOptionsValidator) MarkdownDescription(context.Context) 
string {
+       return "must configure primary keys and partitions with `primary_keys` 
and `partition_keys`"
+}
+
+func (reservedTableOptionsValidator) ValidateMap(_ context.Context, req 
validator.MapRequest, resp *validator.MapResponse) {
+       if req.ConfigValue.IsNull() || req.ConfigValue.IsUnknown() {
+               return
+       }
+       reserved := make([]string, 0, 2)
+       for _, key := range []string{"partition", "primary-key"} {
+               if _, exists := req.ConfigValue.Elements()[key]; exists {
+                       reserved = append(reserved, key)
+               }
+       }
+       if len(reserved) > 0 {
+               resp.Diagnostics.AddAttributeError(
+                       req.Path,
+                       "Reserved Paimon table option",
+                       "Do not configure "+strings.Join(reserved, ", ")+" in 
options. Use partition_keys and primary_keys instead.",
+               )
+       }
+}
+
+func immutableTableOptionsRequiresReplace(_ context.Context, req 
planmodifier.MapRequest, resp *mapplanmodifier.RequiresReplaceIfFuncResponse) {
+       resp.RequiresReplace = immutableTableOptionsChanged(req.StateValue, 
req.PlanValue)
+}
+
+func immutableTableOptionsChanged(before, after types.Map) bool {
+       for key := range immutableTableOptions {
+               beforeValue, beforeExists, beforeKnown := 
knownTableOption(before, key)
+               afterValue, afterExists, afterKnown := knownTableOption(after, 
key)
+               if !beforeKnown || !afterKnown {
+                       continue
+               }
+               if key == "type" && afterExists {

Review Comment:
   Removing an explicitly configured `type = "table"` is semantically identical 
to the default (the code already treats adding `type = "table"` to an absent 
value as a no-op), but this branch only normalizes the case when `afterExists` 
is true. As a result, removing that option makes `immutableTableOptionsChanged` 
require replacement, so Terraform plans to destroy and recreate a managed table 
for a no-op configuration change. `diffTableOptions` has the same asymmetry and 
would otherwise try to remove the immutable option. Please normalize an absent 
planned type to the default `table` in both paths and add the reverse-direction 
regression test.



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