This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.2 by this push:
new 74822216348 branch-4.2: [fix](fe) Fix auto-detect overwrite on
unpartitioned tables #70794 (#70961)
74822216348 is described below
commit 74822216348e28a347f331aec86f0916b9ab1604
Author: Jerry Hu <[email protected]>
AuthorDate: Wed Nov 25 09:25:19 2026 +0800
branch-4.2: [fix](fe) Fix auto-detect overwrite on unpartitioned tables
#70794 (#70961)
### What problem does this PR solve?
Issue Number: None
Related PR: #70794 (cherry-pick to `branch-4.2`)
`INSERT OVERWRITE ... PARTITION(*)` can incorrectly report that a
partition item was dropped concurrently when the target table is
unpartitioned. Temporary partitions of an unpartitioned table
legitimately have no `PartitionItem` or boundary keys, but the shared FE
snapshot check previously rejected every null item.
This backport allows a null item only for `UNPARTITIONED` tables. It
preserves the existing missing-Partition guard and missing-item checks
for RANGE/LIST tables. There are no protocol or persisted-metadata
changes.
The complete source change is included: FE snapshot coverage for valid
unpartitioned temporary partitions and RANGE/LIST metadata checks, plus
full-column and partial-column auto-detect overwrite regression
coverage. Existing regression expected output is unchanged. Test imports
are adapted to the existing branch-4.2 framework.
### Release note
Fix auto-detect `INSERT OVERWRITE ... PARTITION(*)` on unpartitioned
tables incorrectly failing with a concurrent partition-item removal
error.
### Validation
- `./build.sh --be --fe -j 48`: FE/BE build passed with an isolated
third-party overlay and a reduced Java-extension configuration.
- `./run-fe-ut.sh --run
'org.apache.doris.service.FrontendServiceImplTest#testReplacePartitionSnapshotAllowsUnpartitionedTempPartition+testReplacePartitionSnapshotPreservesPartitionItemChecks+testCreatePartitionReturnsRetryErrorWhenResultPartitionIsMissing'`:
3 tests passed with default coverage settings; no failures, errors, or
skips.
- `MAVEN_OPTS='-Xmx12g -Djacoco.skip=true' ./run-fe-ut.sh --run
org.apache.doris.service.FrontendServiceImplTest`: all 28 tests passed;
no failures, errors, or skips.
- SQL regression: `test_iot_unpartitioned_nereids` passed using an
isolated regression configuration on a local single-FE/single-BE
shared-nothing cluster: 1 suite, 0 failed/fatal/skipped. Both
full-column and partial-column `PARTITION(*)` statements executed.
- `(cd fe && mvn -pl fe-core -am checkstyle:check)`: passed with no
violations.
- Diff whitespace check: passed.
Validation limits: coverage-enabled whole-class attempts did not pass;
the final retry failed an authentication assertion also reproduced
against the unmodified target base with the same JMockit/JaCoCo setup.
The focused tests passed with coverage enabled, and disabling only the
optional coverage agent allowed all 28 tests to pass without skipping
tests. The local SQL run used `enable_java_support=false` with the
reduced Java-extension build; Java UDF/HDFS integrations, Cloud mode,
multiple BEs, and mixed-version deployments were not validated.
### Check List (For Author)
- Test:
- [x] Unit Test
- [x] Regression test
- Behavior changed:
- [x] Yes. Valid unpartitioned auto-detect overwrite no longer raises a
false concurrent-removal error; partitioned-table metadata checks are
unchanged.
- Does this need documentation?
- [x] No.
---
.../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 ce519967b18..34f9eafe8ae 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
@@ -4790,7 +4790,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 c8324303961..1f844252a76 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
@@ -22,6 +22,7 @@ import org.apache.doris.catalog.Database;
import org.apache.doris.catalog.Env;
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.cloud.CacheHotspotManager;
import org.apache.doris.cloud.catalog.CloudEnv;
@@ -29,10 +30,12 @@ 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.PrintableMap;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.datasource.maxcompute.MCTransaction;
import org.apache.doris.datasource.maxcompute.MaxComputeExternalCatalog;
+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;
@@ -64,6 +67,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;
@@ -100,10 +104,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.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
@@ -576,6 +582,94 @@ public class FrontendServiceImplTest {
}
}
+ @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]