OIiveirra commented on code in PR #69408:
URL: https://github.com/apache/doris/pull/69408#discussion_r4346437278


##########
fe/fe-core/src/main/java/org/apache/doris/datasource/iceberg/IcebergRestSchemaCommit.java:
##########
@@ -0,0 +1,118 @@
+// 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 org.apache.doris.datasource.iceberg;
+
+import com.fasterxml.jackson.annotation.JsonAutoDetect;
+import com.fasterxml.jackson.annotation.PropertyAccessor;
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonFactoryBuilder;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+import com.google.common.base.Preconditions;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.TableMetadata;
+import org.apache.iceberg.TableOperations;
+import org.apache.iceberg.UpdateRequirement;
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.RESTSerializers;
+import org.apache.iceberg.rest.RESTSessionCatalog;
+import org.apache.iceberg.rest.RESTUtil;
+import org.apache.iceberg.rest.requests.UpdateTableRequest;
+import org.apache.iceberg.rest.requests.UpdateTableRequestParser;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+/** Adds a partition-counter precondition to a DROP request without persisting 
a partition spec. */
+public final class IcebergRestSchemaCommit {
+    private static final ThreadLocal<TableMetadata> DROP_BASE = new 
ThreadLocal<>();
+
+    private IcebergRestSchemaCommit() {
+    }
+
+    public static RESTSessionCatalog newSessionCatalog() {
+        return new GuardedSessionCatalog();
+    }
+
+    static boolean supports(RESTSessionCatalog catalog) {
+        return catalog instanceof GuardedSessionCatalog;
+    }
+
+    static void commit(TableOperations operations, TableMetadata base, 
TableMetadata update) {
+        Preconditions.checkState(DROP_BASE.get() == null, "Nested Iceberg REST 
schema DROP commit");
+        DROP_BASE.set(base);
+        try {
+            // The synchronous SDK commit keeps its endpoint, table auth 
session, mutation headers,
+            // response handling and cached metadata. Only the serialized 
request gains a requirement.
+            operations.commit(base, update);
+        } finally {
+            DROP_BASE.remove();
+        }
+    }
+
+    static ObjectMapper newMapper() {
+        // Match Iceberg 1.11.0 RESTObjectMapper using public APIs, then 
specialize only table updates.
+        JsonFactory factory = new JsonFactoryBuilder()
+                .configure(JsonFactory.Feature.INTERN_FIELD_NAMES, false)
+                .configure(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, 
false).build();
+        ObjectMapper mapper = new ObjectMapper(factory);
+        mapper.setVisibility(PropertyAccessor.FIELD, 
JsonAutoDetect.Visibility.ANY);
+        mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, 
false);
+        mapper.setPropertyNamingStrategy(new 
PropertyNamingStrategies.KebabCaseStrategy());
+        RESTSerializers.registerAll(mapper);
+        SimpleModule module = new SimpleModule("doris-iceberg-schema-drop");
+        module.addSerializer(UpdateTableRequest.class, new 
DropRequestSerializer());
+        mapper.registerModule(module);
+        return mapper;
+    }
+
+    private static final class GuardedSessionCatalog extends 
RESTSessionCatalog {
+        private GuardedSessionCatalog() {
+            super(properties -> 
HTTPClient.builder(properties).uri(properties.get(CatalogProperties.URI))
+                    
.withHeaders(RESTUtil.configHeaders(properties)).withObjectMapper(newMapper()).build(),
 null);
+        }
+    }
+
+    private static final class DropRequestSerializer extends 
JsonSerializer<UpdateTableRequest> {
+        @Override
+        public void serialize(UpdateTableRequest request, JsonGenerator 
generator, SerializerProvider provider)
+                throws IOException {
+            TableMetadata base = DROP_BASE.get();
+            UpdateTableRequest serialized = request;
+            if (base != null) {
+                // A scoped commit may serialize only the table whose 
validated metadata it pinned.
+                
Preconditions.checkState(request.requirements().stream().anyMatch(requirement ->
+                        requirement instanceof 
UpdateRequirement.AssertTableUUID
+                                && 
Objects.equals(((UpdateRequirement.AssertTableUUID) requirement).uuid(),
+                                        base.uuid())),
+                        "Iceberg REST schema DROP request does not match its 
validated table");
+                List<UpdateRequirement> requirements = new 
ArrayList<>(request.requirements());
+                requirements.add(new 
UpdateRequirement.AssertLastAssignedPartitionId(base.lastAssignedPartitionId()));

Review Comment:
   Implemented the explicit `TableCommit` approach in 
`9f45d8fcfd7af50433ad6c64cdb9ce8fa79bdb5e`, using the official pinned Iceberg 
1.11.0 API with unchanged dependencies.
   
   REST DROP now builds the normal SDK requirements plus 
`AssertLastAssignedPartitionId` from the exact validated base, includes the 
complete staged changes and identifier, and submits one commit through the 
retained `RESTSessionCatalog.commitTransaction`. The ThreadLocal, copied mapper 
and guarded catalog are removed. The writable generation and authenticator 
remain retained; session mode and delegated-token policy come from that 
generation, including concurrent catalog reconfiguration. ADD/RENAME and 
non-REST commits retain their existing paths.
   
   After success, the bound SDK catalog is invalidated and Doris metadata is 
refreshed. Failures after the remote commit explicitly report that DROP already 
committed. The real HTTP tests cover the request requirements, concurrent 
partition rejection, consecutive drops/reload, catalog and delegated 
authentication, table-token-only rejection, generation changes, refresh 
failures and unsupported endpoints.
   
   The compatibility boundary is explicit in the PR body/release note: REST 
DROP requires a transaction endpoint and contextual catalog/user transaction 
permission. The SDK transaction API does not inherit table-specific HTTP 
credentials. Unsupported endpoints or authorization failures do not fall back 
to an unguarded ordinary commit. The official REST fixture supports the 
endpoint; a controlled table-token-only HTTP service demonstrates the 
authentication limitation, without claiming coverage of untested vendors.
   
   Validation: 367 focused FE tests passed (including 18 public-DROP HTTP 
tests), Checkstyle passed. The standard ASAN BE+FE build and both complete 
native suites (`iceberg_schema_change_ddl` and 
`test_iceberg_delete_unpartitioned_evolution`) passed with fresh isolated FE/BE 
state and verified final artifact/process identity; zero failed or skipped 
suites. Expected regression outputs were unchanged.
   
   Leaving this thread unresolved for your review of the implementation.
   



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

Reply via email to