This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.1 by this push:
new e1039662cb1 branch-4.1: [fix](fe) Reject static partition assignments
for OLAP tables #70287 (#70399)
e1039662cb1 is described below
commit e1039662cb1371bdea96439049901aa28520d423
Author: yujun <[email protected]>
AuthorDate: Tue Nov 17 10:37:14 2026 +0800
branch-4.1: [fix](fe) Reject static partition assignments for OLAP tables
#70287 (#70399)
cherry-pick: #70287
---
.../nereids/analyzer/UnboundTableSinkCreator.java | 9 ++
.../analyzer/UnboundTableSinkCreatorTest.java | 105 +++++++++++++++++++++
.../test_olap_static_partition_rejected.out | 21 +++++
.../test_olap_static_partition_rejected.groovy | 75 +++++++++++++++
4 files changed, 210 insertions(+)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreator.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreator.java
index 3f535fe46f2..eb44c7540a9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreator.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreator.java
@@ -95,6 +95,7 @@ public class UnboundTableSinkCreator {
String catalogName =
RelationUtil.getQualifierName(ConnectContext.get(), nameParts).get(0);
CatalogIf<?> curCatalog =
Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
if (curCatalog instanceof InternalCatalog) {
+ rejectStaticPartitionForOlapTable(staticPartitionKeyValues);
return new UnboundTableSink<>(nameParts, colNames, hints,
temporaryPartition, partitions,
isPartialUpdate, partialUpdateNewKeyPolicy,
dmlCommandType, Optional.empty(),
Optional.empty(), plan);
@@ -138,6 +139,7 @@ public class UnboundTableSinkCreator {
String catalogName =
RelationUtil.getQualifierName(ConnectContext.get(), nameParts).get(0);
CatalogIf<?> curCatalog =
Env.getCurrentEnv().getCatalogMgr().getCatalog(catalogName);
if (curCatalog instanceof InternalCatalog) {
+ rejectStaticPartitionForOlapTable(staticPartitionKeyValues);
return new UnboundTableSink<>(nameParts, colNames, hints,
temporaryPartition, partitions,
isAutoDetectPartition,
isPartialUpdate, partialUpdateNewKeyPolicy,
dmlCommandType, Optional.empty(),
@@ -167,6 +169,13 @@ public class UnboundTableSinkCreator {
? " PARTITION(*) is only supported in overwrite
partition for OLAP table" : ""));
}
+ private static void rejectStaticPartitionForOlapTable(Map<String,
Expression> staticPartitionKeyValues) {
+ if (staticPartitionKeyValues != null &&
!staticPartitionKeyValues.isEmpty()) {
+ throw new AnalysisException("Static partition syntax PARTITION
(column=value) is not supported for OLAP "
+ + "tables. Specify partition names instead, or use
PARTITION (*) for INSERT OVERWRITE.");
+ }
+ }
+
private static void validatePaimonPartitionSyntax(boolean
temporaryPartition,
List<String> partitions) {
if (temporaryPartition) {
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreatorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreatorTest.java
new file mode 100644
index 00000000000..597ef7f5af1
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/analyzer/UnboundTableSinkCreatorTest.java
@@ -0,0 +1,105 @@
+// 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.nereids.analyzer;
+
+import org.apache.doris.catalog.Env;
+import org.apache.doris.datasource.CatalogIf;
+import org.apache.doris.datasource.CatalogMgr;
+import org.apache.doris.datasource.InternalCatalog;
+import org.apache.doris.datasource.hive.HMSExternalCatalog;
+import org.apache.doris.nereids.exceptions.AnalysisException;
+import org.apache.doris.nereids.trees.expressions.Alias;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.nereids.trees.plans.commands.info.DMLCommandType;
+import org.apache.doris.nereids.trees.plans.logical.LogicalOneRowRelation;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.mockito.MockedStatic;
+import org.mockito.Mockito;
+
+import java.util.List;
+import java.util.Map;
+
+public class UnboundTableSinkCreatorTest {
+
+ private static final List<String> NAME_PARTS = ImmutableList.of("cat",
"db", "tbl");
+
+ @Test
+ public void staticPartitionIsRejectedForOlapTables() {
+ for (CatalogIf<?> catalog :
ImmutableList.of(Mockito.mock(InternalCatalog.class))) {
+ withCatalog(catalog, () -> {
+ LogicalOneRowRelation query = new LogicalOneRowRelation(new
RelationId(1),
+ ImmutableList.of(new Alias(Literal.of(1))));
+ Map<String, Expression> staticPartitions =
ImmutableMap.of("dt", Literal.of("2026-11-04"));
+ AnalysisException exception =
Assertions.assertThrows(AnalysisException.class,
+ () -> UnboundTableSinkCreator.createUnboundTableSink(
+ NAME_PARTS, ImmutableList.of(),
ImmutableList.of(), false,
+ ImmutableList.of(), false, null,
DMLCommandType.INSERT, query, staticPartitions));
+ Assertions.assertTrue(exception.getMessage().contains(
+ "Static partition syntax PARTITION (column=value) is
not supported for OLAP tables"));
+ for (boolean overwrite : new boolean[] {false, true}) {
+ AnalysisException overwriteException =
Assertions.assertThrows(AnalysisException.class,
+ () ->
UnboundTableSinkCreator.createUnboundTableSinkMaybeOverwrite(
+ NAME_PARTS, ImmutableList.of(),
ImmutableList.of(), false,
+ ImmutableList.of(), false, overwrite,
false, null,
+ DMLCommandType.INSERT, query,
staticPartitions));
+ Assertions.assertEquals(exception.getMessage(),
overwriteException.getMessage());
+ }
+ });
+ }
+ }
+
+ @Test
+ public void staticPartitionIsPreservedForHiveTables() {
+ withCatalog(Mockito.mock(HMSExternalCatalog.class), () -> {
+ LogicalOneRowRelation query = new LogicalOneRowRelation(new
RelationId(1),
+ ImmutableList.of(new Alias(Literal.of(1))));
+ Map<String, Expression> staticPartitions = ImmutableMap.of("dt",
Literal.of("2026-11-04"));
+ UnboundHiveTableSink<?> sink = (UnboundHiveTableSink<?>)
+ UnboundTableSinkCreator.createUnboundTableSink(
+ NAME_PARTS, ImmutableList.of(),
ImmutableList.of(), false,
+ ImmutableList.of(), false, null,
DMLCommandType.INSERT, query, staticPartitions);
+ Assertions.assertEquals(staticPartitions,
sink.getStaticPartitionKeyValues());
+ for (boolean overwrite : new boolean[] {false, true}) {
+ UnboundHiveTableSink<?> overwriteSink =
(UnboundHiveTableSink<?>)
+
UnboundTableSinkCreator.createUnboundTableSinkMaybeOverwrite(
+ NAME_PARTS, ImmutableList.of(),
ImmutableList.of(), false,
+ ImmutableList.of(), false, overwrite, false,
null,
+ DMLCommandType.INSERT, query,
staticPartitions);
+ Assertions.assertEquals(staticPartitions,
overwriteSink.getStaticPartitionKeyValues());
+ }
+ });
+ }
+
+ private void withCatalog(CatalogIf<?> catalog, Runnable action) {
+ CatalogMgr catalogMgr = Mockito.mock(CatalogMgr.class);
+ Mockito.<Object>when(catalogMgr.getCatalog("cat")).thenReturn(catalog);
+ Env env = Mockito.mock(Env.class);
+ Mockito.when(env.getCatalogMgr()).thenReturn(catalogMgr);
+ try (MockedStatic<Env> envMock = Mockito.mockStatic(Env.class)) {
+ envMock.when(Env::getCurrentEnv).thenReturn(env);
+ action.run();
+ }
+ }
+
+}
diff --git
a/regression-test/data/insert_overwrite_p0/test_olap_static_partition_rejected.out
b/regression-test/data/insert_overwrite_p0/test_olap_static_partition_rejected.out
new file mode 100644
index 00000000000..0cf60dd5d4c
--- /dev/null
+++
b/regression-test/data/insert_overwrite_p0/test_olap_static_partition_rejected.out
@@ -0,0 +1,21 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !after_rejected_statements --
+4 2026-11-04
+5 2026-11-05
+
+-- !insert_by_name --
+4 2026-11-04
+41 2026-11-04
+5 2026-11-05
+
+-- !overwrite_by_name --
+42 2026-11-04
+5 2026-11-05
+
+-- !overwrite_auto_detect --
+43 2026-11-04
+5 2026-11-05
+
+-- !overwrite_whole_table --
+44 2026-11-04
+
diff --git
a/regression-test/suites/insert_overwrite_p0/test_olap_static_partition_rejected.groovy
b/regression-test/suites/insert_overwrite_p0/test_olap_static_partition_rejected.groovy
new file mode 100644
index 00000000000..ca2a04fcded
--- /dev/null
+++
b/regression-test/suites/insert_overwrite_p0/test_olap_static_partition_rejected.groovy
@@ -0,0 +1,75 @@
+// 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.
+
+suite("test_olap_static_partition_rejected") {
+ sql "DROP TABLE IF EXISTS test_olap_static_partition_rejected"
+ sql """
+ CREATE TABLE test_olap_static_partition_rejected (
+ id INT,
+ dt DATE NOT NULL
+ ) DUPLICATE KEY(id)
+ PARTITION BY RANGE(dt) (
+ PARTITION p20261104 VALUES [('2026-11-04'), ('2026-11-05')),
+ PARTITION p20261105 VALUES [('2026-11-05'), ('2026-11-06'))
+ )
+ DISTRIBUTED BY HASH(id) BUCKETS 1
+ PROPERTIES ("replication_num" = "1")
+ """
+ sql "INSERT INTO test_olap_static_partition_rejected VALUES (4,
'2026-11-04'), (5, '2026-11-05')"
+
+ test {
+ sql "SELECT * FROM test_olap_static_partition_rejected
PARTITION(`dt`='2026-11-04')"
+ exception "mismatched input '='"
+ }
+ test {
+ sql """INSERT INTO test_olap_static_partition_rejected
PARTITION(`dt`='2026-11-04')
+ VALUES (40, '2026-11-04')"""
+ exception "Static partition syntax PARTITION (column=value) is not
supported for OLAP tables"
+ }
+ test {
+ sql """INSERT INTO test_olap_static_partition_rejected
PARTITION(`dt`='2026-11-04')
+ SELECT 40, CAST('2026-11-05' AS DATE)"""
+ exception "Static partition syntax PARTITION (column=value) is not
supported for OLAP tables"
+ }
+ test {
+ sql """INSERT OVERWRITE TABLE test_olap_static_partition_rejected
PARTITION(`dt`='2026-11-04')
+ SELECT 40, CAST('2026-11-04' AS DATE)"""
+ exception "Static partition syntax PARTITION (column=value) is not
supported for OLAP tables"
+ }
+ test {
+ sql """INSERT OVERWRITE TABLE test_olap_static_partition_rejected
PARTITION(`dt`='2026-11-04')
+ SELECT id, dt FROM test_olap_static_partition_rejected WHERE 1
= 0"""
+ exception "Static partition syntax PARTITION (column=value) is not
supported for OLAP tables"
+ }
+ order_qt_after_rejected_statements "SELECT * FROM
test_olap_static_partition_rejected"
+
+ sql """INSERT INTO test_olap_static_partition_rejected PARTITION(p20261104)
+ VALUES (41, '2026-11-04')"""
+ order_qt_insert_by_name "SELECT * FROM test_olap_static_partition_rejected"
+
+ sql """INSERT OVERWRITE TABLE test_olap_static_partition_rejected
PARTITION(p20261104)
+ SELECT 42, CAST('2026-11-04' AS DATE)"""
+ order_qt_overwrite_by_name "SELECT * FROM
test_olap_static_partition_rejected"
+
+ sql """INSERT OVERWRITE TABLE test_olap_static_partition_rejected
PARTITION(*)
+ SELECT 43, CAST('2026-11-04' AS DATE)"""
+ order_qt_overwrite_auto_detect "SELECT * FROM
test_olap_static_partition_rejected"
+
+ sql """INSERT OVERWRITE TABLE test_olap_static_partition_rejected
+ SELECT 44, CAST('2026-11-04' AS DATE)"""
+ order_qt_overwrite_whole_table "SELECT * FROM
test_olap_static_partition_rejected"
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]