branch-2.1: [fix](partition) Incorrectly add partition to non-partitioned table #48121 (#48323)

Cherry-picked from #48121

Co-authored-by: Uniqueyou <wangyixuan@selectdb.com>
This commit is contained in:
github-actions[bot]
2025-02-26 20:28:45 +08:00
committed by GitHub
parent b1ac39587b
commit a5adb8ec69
3 changed files with 41 additions and 3 deletions

View File

@ -1524,6 +1524,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();
/*

View File

@ -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);
}
}

View File

@ -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"
}
}