This is an automated email from the ASF dual-hosted git repository.

HappenLee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8effcaa20f9 [fix](fe) Fix auto-detect overwrite on unpartitioned 
tables (#70794)
8effcaa20f9 is described below

commit 8effcaa20f972c9b91d486346d32a3b2df3ae5cc
Author: Jerry Hu <[email protected]>
AuthorDate: Tue Nov 24 12:03:47 2026 +0800

    [fix](fe) Fix auto-detect overwrite on unpartitioned tables (#70794)
    
    ### Background
    
    Auto-detect overwrite (`INSERT OVERWRITE ... PARTITION(*)`) creates
    temporary partitions for the partitions reached by the input rows. The
    FE snapshots their partition and tablet metadata under the table read
    lock and returns it to the BE. Unpartitioned temporary partitions have
    no partition boundary item.
    
    ### What problem does this PR solve?
    
    Issue Number: None
    Related PR: #65282 (introduced the check), #65956 (backport to
    branch-4.1)
    PR Type: Bugfix
    
    Problem Summary:
    
    Auto-detect overwrite on an unpartitioned table can fail with a
    misleading concurrent-drop error even without any concurrent DDL. Allow
    its legitimate null partition item while retaining missing-partition and
    missing-item checks for partitioned tables. Most of the diff verifies
    real temporary-partition metadata and exercises repeated unpartitioned
    auto-detect overwrite.
    
    ### Details
    
    - **Frequency:** Reproduced deterministically in the local FE metadata
    test: snapshotting an unpartitioned overwrite temporary partition fails
    without concurrent DDL.
    - **Root cause:** `snapshotPartitionResult` unconditionally rejects a
    missing `PartitionItem`, although `SinglePartitionInfo` deliberately
    creates none for temporary partitions. `OlapTableSink.setPartitionKeys`
    already accepts that case and sends no boundary keys.
    - **Why existing tests missed it:** `FrontendServiceImplTest` covers
    dropped auto RANGE partitions, but not unpartitioned temporary
    snapshots. The auto-detect regression covers RANGE/LIST, while the
    unpartitioned regression previously used ordinary overwrite only.
    - **Fix:** Require a non-null item only when the partition type is not
    `UNPARTITIONED`. Keep the existing table lock and missing `Partition`
    checks unchanged.
    - **Other paths and branches:** The shared helper covers both
    snapshot-by-name and snapshot-by-id, in cloud and shared-nothing mode.
    The unconditional check is present on branch-4.1 and branch-4.2;
    branch-3.1 and branch-4.0 do not have this helper/check. No wire or
    persisted format changes.
    
    ### Testing
    
    - Added FE tests for a real unpartitioned temporary partition,
    RANGE/LIST boundary preservation, and missing RANGE/LIST items. On the
    compiled baseline, 2 test methods ran: the unpartitioned case failed
    with the exact concurrent-drop error, while the RANGE/LIST positive and
    negative cases passed. On the candidate, both new methods and the
    existing missing-Partition guard test passed: 3 methods, 0
    failures/errors/skips; the complete preset UT command exited
    successfully.
    - Updated `test_iot_unpartitioned_nereids` to exercise auto-detect
    overwrite with full and partial columns. Existing expected rows remain
    unchanged; SQL regression has not run: the isolated cluster build did
    not complete its third-party dependency download within a 180-second
    bounded attempt.
    
    ### Notes for Reviewers
    
    The missing-item check must not be removed for RANGE/LIST tables. A null
    item is allowed only for the unpartitioned case.
    
    ### Release note
    
    Fix auto-detect overwrite incorrectly reporting a concurrent partition
    drop for unpartitioned tables.
    
    ### Check List (For Author)
    
    - Behavior changed: No
    - Does this need documentation: No
    - Pre-submission status: Partially verified: SQL regression, cloud
    deployment, and mixed-version validation have not run.
    
    ### AI Disclosure
    
    - Tool: Codex
    - Generated: code, tests, and this description
    - Human review: not stated
---
 .../apache/doris/service/FrontendServiceImpl.java  |  3 +-
 .../doris/service/FrontendServiceImplTest.java     | 94 ++++++++++++++++++++++
 ...rt_overwrite_table_unpartitioned_nereids.groovy |  8 +-
 3 files changed, 100 insertions(+), 5 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java 
b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
index 7fd88db0fad..fdfe3248bbe 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/service/FrontendServiceImpl.java
@@ -5473,7 +5473,8 @@ public class FrontendServiceImpl implements 
FrontendService.Iface {
             boolean enableAdaptiveRandomBucket, String resultName) throws 
UserException {
         long partitionId = partition.getId();
         PartitionItem partitionItem = partitionInfo.getItem(partitionId);
-        if (partitionItem == null) {
+        // Unpartitioned temporary partitions have no partition item or 
boundary keys.
+        if (partitionItem == null && partitionInfo.getType() != 
PartitionType.UNPARTITIONED) {
             throw new UserException(String.format(
                     "partition item of %s was dropped concurrently while 
building %s result, please retry",
                     partitionLabel, resultName));
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
index a55eded6c6a..b1fd37e0a0c 100644
--- 
a/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/service/FrontendServiceImplTest.java
@@ -23,6 +23,7 @@ import org.apache.doris.catalog.Env;
 import org.apache.doris.catalog.MaterializedIndex;
 import org.apache.doris.catalog.OlapTable;
 import org.apache.doris.catalog.Partition;
+import org.apache.doris.catalog.PartitionItem;
 import org.apache.doris.catalog.TableIf;
 import org.apache.doris.catalog.Tablet;
 import org.apache.doris.cloud.catalog.CloudPartition;
@@ -30,8 +31,10 @@ import org.apache.doris.common.AuthenticationException;
 import org.apache.doris.common.Config;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.FeConstants;
+import org.apache.doris.common.UserException;
 import org.apache.doris.common.util.DatasourcePrintableMap;
 import org.apache.doris.datasource.InternalCatalog;
+import org.apache.doris.insertoverwrite.InsertOverwriteUtil;
 import org.apache.doris.mysql.authenticate.TestLogAppender;
 import org.apache.doris.nereids.parser.NereidsParser;
 import org.apache.doris.nereids.trees.plans.commands.Command;
@@ -60,6 +63,7 @@ import org.apache.doris.thrift.TMaxComputeBlockIdResult;
 import org.apache.doris.thrift.TMetadataTableRequestParams;
 import org.apache.doris.thrift.TMetadataType;
 import org.apache.doris.thrift.TNullableStringLiteral;
+import org.apache.doris.thrift.TOlapTablePartition;
 import org.apache.doris.thrift.TPrivilegeCtrl;
 import org.apache.doris.thrift.TPrivilegeHier;
 import org.apache.doris.thrift.TPrivilegeType;
@@ -94,10 +98,12 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
@@ -815,6 +821,94 @@ public class FrontendServiceImplTest extends 
TestWithFeService {
         }
     }
 
+    @Test
+    public void testReplacePartitionSnapshotAllowsUnpartitionedTempPartition() 
throws Exception {
+        createTable("CREATE TABLE test.replace_snapshot_unpartitioned (k INT) "
+                + "DISTRIBUTED BY HASH(k) BUCKETS 1 
PROPERTIES(\"replication_num\" = \"1\")");
+        Database db = 
Env.getCurrentInternalCatalog().getDbOrAnalysisException("test");
+        OlapTable table = (OlapTable) 
db.getTableOrAnalysisException("replace_snapshot_unpartitioned");
+        InsertOverwriteUtil.addTempPartitions(table, 
Collections.singletonList(table.getName()),
+                Collections.singletonList("replace_snapshot_temp"));
+        Partition tempPartition = table.getPartition("replace_snapshot_temp", 
true);
+        Assertions.assertNotNull(tempPartition);
+        
Assertions.assertNull(table.getPartitionInfo().getItem(tempPartition.getId()));
+
+        TOlapTablePartition result = snapshotReplacePartition(table, 
tempPartition.getId());
+        Assertions.assertEquals(tempPartition.getId(), result.getId());
+        Assertions.assertEquals(1, result.getIndexesSize());
+        Assertions.assertEquals(1, result.getNumBuckets());
+        Assertions.assertFalse(result.isSetStartKeys());
+        Assertions.assertFalse(result.isSetEndKeys());
+        Assertions.assertFalse(result.isSetInKeys());
+    }
+
+    @Test
+    public void testReplacePartitionSnapshotPreservesPartitionItemChecks() 
throws Exception {
+        for (String partitionType : Arrays.asList("RANGE", "LIST")) {
+            String tableName = "replace_snapshot_" + 
partitionType.toLowerCase(Locale.ROOT);
+            String partitionClause = partitionType.equals("RANGE")
+                    ? "PARTITION BY RANGE(k) (PARTITION p1 VALUES LESS THAN 
(10)) "
+                    : "PARTITION BY LIST(k) (PARTITION p1 VALUES IN (1)) ";
+            createTable("CREATE TABLE test." + tableName + " (k INT) " + 
partitionClause
+                    + "DISTRIBUTED BY HASH(k) BUCKETS 1 
PROPERTIES(\"replication_num\" = \"1\")");
+            Database db = 
Env.getCurrentInternalCatalog().getDbOrAnalysisException("test");
+            OlapTable table = (OlapTable) 
db.getTableOrAnalysisException(tableName);
+            InsertOverwriteUtil.addTempPartitions(table, 
Collections.singletonList("p1"),
+                    Collections.singletonList("replace_snapshot_temp"));
+            Partition tempPartition = 
table.getPartition("replace_snapshot_temp", true);
+            Assertions.assertNotNull(tempPartition);
+            
Assertions.assertNotNull(table.getPartitionInfo().getItem(tempPartition.getId()));
+            TOlapTablePartition result = snapshotReplacePartition(table, 
tempPartition.getId());
+            Assertions.assertEquals(tempPartition.getId(), result.getId());
+            if (partitionType.equals("RANGE")) {
+                Assertions.assertEquals(10, 
result.getEndKeys().get(0).getIntLiteral().getValue());
+            } else {
+                Assertions.assertEquals(1, 
result.getInKeys().get(0).get(0).getIntLiteral().getValue());
+            }
+
+            // Model a missing item without removing the temporary Partition 
object.
+            PartitionItem item = 
table.getPartitionInfo().getItem(tempPartition.getId());
+            table.writeLock();
+            try {
+                table.getPartitionInfo().setItem(tempPartition.getId(), true, 
null);
+            } finally {
+                table.writeUnlock();
+            }
+            try {
+                InvocationTargetException exception = 
Assertions.assertThrows(InvocationTargetException.class,
+                        () -> snapshotReplacePartition(table, 
tempPartition.getId()));
+                UserException cause = 
Assertions.assertInstanceOf(UserException.class, exception.getCause());
+                Assertions.assertEquals("partition item of " + 
tempPartition.getId()
+                        + " was dropped concurrently while building replace 
partition result, please retry",
+                        cause.getDetailMessage());
+            } finally {
+                table.writeLock();
+                try {
+                    table.getPartitionInfo().setItem(tempPartition.getId(), 
true, item);
+                } finally {
+                    table.writeUnlock();
+                }
+            }
+        }
+    }
+
+    private static TOlapTablePartition snapshotReplacePartition(OlapTable 
table, long partitionId) throws Exception {
+        Method method = 
FrontendServiceImpl.class.getDeclaredMethod("snapshotPartitionResultsById",
+                OlapTable.class, Collection.class, boolean.class, 
boolean.class, String.class);
+        method.setAccessible(true);
+        table.readLock();
+        try {
+            List<?> snapshots = (List<?>) method.invoke(null, table, 
Collections.singletonList(partitionId),
+                    false, false, "replace partition");
+            Assertions.assertEquals(1, snapshots.size());
+            Field field = 
snapshots.get(0).getClass().getDeclaredField("tPartition");
+            field.setAccessible(true);
+            return (TOlapTablePartition) field.get(snapshots.get(0));
+        } finally {
+            table.readUnlock();
+        }
+    }
+
     @Test
     public void testCreatePartitionList() throws Exception {
         String createOlapTblStmt = new String("CREATE TABLE 
test.partition_list(\n"
diff --git 
a/regression-test/suites/insert_overwrite_p0/insert_overwrite_table_unpartitioned_nereids.groovy
 
b/regression-test/suites/insert_overwrite_p0/insert_overwrite_table_unpartitioned_nereids.groovy
index 7142910da03..c40f19367e3 100644
--- 
a/regression-test/suites/insert_overwrite_p0/insert_overwrite_table_unpartitioned_nereids.groovy
+++ 
b/regression-test/suites/insert_overwrite_p0/insert_overwrite_table_unpartitioned_nereids.groovy
@@ -96,13 +96,13 @@ suite("test_iot_unpartitioned_nereids") {
         sql """INSERT OVERWRITE TABLE test_iot select 1,'aaa','aaa' """
         order_qt_select """select * from test_iot"""
        
-        // overwrite with another table
+        // Auto-detect overwrite must also support unpartitioned temporary 
partitions.
         sql """ INSERT INTO test_iot1(test_int, test_varchar, test_text) 
VALUES (1,'aaa','aaa'),(4,'ccc','ccc') """
-        sql """INSERT OVERWRITE TABLE test_iot select * from test_iot1"""
+        sql """INSERT OVERWRITE TABLE test_iot PARTITION(*) select * from 
test_iot1"""
         order_qt_select """select * from test_iot"""
        
-        // overwrite table with some cols
-        sql """INSERT OVERWRITE TABLE test_iot (test_int, test_varchar) select 
test_int, test_varchar from test_iot1"""
+        // Repeat auto-detect overwrite with partial columns, including 
default NULLs.
+        sql """INSERT OVERWRITE TABLE test_iot PARTITION(*) (test_int, 
test_varchar) select test_int, test_varchar from test_iot1"""
         order_qt_select """select * from test_iot"""
 
        // overwrite with label


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to