This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new 3cf8ad212e5 branch-3.0: [fix](partition) Incorrectly add partition to non-partitioned table #48121 (#48322) 3cf8ad212e5 is described below commit 3cf8ad212e54d244f587a74e2e47f2184fc5d253 Author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> AuthorDate: Wed Feb 26 10:15:45 2025 +0800 branch-3.0: [fix](partition) Incorrectly add partition to non-partitioned table #48121 (#48322) Cherry-picked from #48121 Co-authored-by: Uniqueyou <wangyix...@selectdb.com> --- .../apache/doris/datasource/InternalCatalog.java | 5 ++++ .../apache/doris/alter/AddExistsPartitionTest.java | 7 +++-- .../test_add_partition_exception.groovy | 32 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index b6dc35b4562..92a40fe6857 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -1604,6 +1604,11 @@ public class InternalCatalog implements CatalogIf<Database> { } } + if (partitionInfo.getType() != PartitionType.RANGE && partitionInfo.getType() != PartitionType.LIST + && !isTempPartition) { + throw new DdlException("Alter table [" + olapTable.getName() + "] failed. Not a partitioned table"); + } + Map<String, String> properties = singlePartitionDesc.getProperties(); /* diff --git a/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java b/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java index 841dd099d22..0d5cc27d3dc 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/alter/AddExistsPartitionTest.java @@ -43,13 +43,14 @@ public class AddExistsPartitionTest extends TestWithFeService { public void testAddExistsPartition() throws Exception { DebugPointUtil.addDebugPoint("InternalCatalog.addPartition.noCheckExists", new DebugPoint()); createDatabase("test"); - createTable("CREATE TABLE test.tbl (k INT) DISTRIBUTED BY HASH(k) " + createTable("CREATE TABLE test.tbl (k INT) PARTITION BY LIST(`k`) ( PARTITION tbl values in ((1)) ) " + + "DISTRIBUTED BY HASH(k) " + " BUCKETS 5 PROPERTIES ( \"replication_num\" = \"" + backendNum() + "\" )"); List<Long> backendIds = Env.getCurrentSystemInfo().getAllBackendIds(); Map<Long, Set<Long>> oldBackendTablets = Maps.newHashMap(); for (long backendId : backendIds) { Set<Long> tablets = Sets.newHashSet(Env.getCurrentInvertedIndex().getTabletIdsByBackendId(backendId)); - Assertions.assertEquals(5, tablets.size()); + Assertions.assertEquals(5, tablets.size()); oldBackendTablets.put(backendId, tablets); } @@ -58,7 +59,7 @@ public class AddExistsPartitionTest extends TestWithFeService { Assertions.assertNotNull(getSqlStmtExecutor(addPartitionSql)); for (long backendId : backendIds) { Set<Long> tablets = Sets.newHashSet(Env.getCurrentInvertedIndex().getTabletIdsByBackendId(backendId)); - Assertions.assertEquals(5, tablets.size()); + Assertions.assertEquals(5, tablets.size()); Assertions.assertEquals(oldBackendTablets.get(backendId), tablets); } } diff --git a/regression-test/suites/partition_p0/no_partition/test_add_partition_exception.groovy b/regression-test/suites/partition_p0/no_partition/test_add_partition_exception.groovy new file mode 100644 index 00000000000..57a0bf241f1 --- /dev/null +++ b/regression-test/suites/partition_p0/no_partition/test_add_partition_exception.groovy @@ -0,0 +1,32 @@ +// 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_add_partition_exception") { + sql "drop table if exists test_add_partition_exception_tbl" + sql """ + CREATE TABLE IF NOT EXISTS test_add_partition_exception_tbl ( + k1 int NOT NULL, + k2 bigint NOT NULL + ) + DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1") + """ + + test{ + sql """ alter table test_add_partition_exception_tbl add partition p0 values in (("1"))""" + exception "Alter table [test_add_partition_exception_tbl] failed. Not a partitioned table" + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org