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


##########
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:
   Fixed in 3da5003. Both missing sides now normalize to the effective default 
`table` for replacement planning, and `diffTableOptions` suppresses the reverse 
removeOption no-op as well. Added regression coverage for explicit `table` to 
absent in both paths.



##########
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:
   Fixed in 3da5003. User field IDs are now capped at 1073741822, immediately 
below `SpecialFields.SYSTEM_FIELD_ID_START` (1073741823), in both provider 
allocation validation and client nested-ID generation. Added tests for the 
maximum valid ID, the first reserved ID, and nested allocation crossing the 
boundary.



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