branch-2.1: [fix](partition) Add partition of mismatched type to table #47200 (#48066)

pick: https://github.com/apache/doris/pull/47200
This commit is contained in:
Uniqueyou
2025-02-19 19:17:58 +08:00
committed by GitHub
parent b2143d05c2
commit 4a39b2b338
4 changed files with 59 additions and 0 deletions

View File

@ -144,6 +144,10 @@ public class PartitionKeyDesc {
return partitionKeyValueType;
}
public boolean hasInValues() {
return inValues != null;
}
public void analyze(int partColNum) throws AnalysisException {
if (isDummy()) {
return;

View File

@ -74,6 +74,10 @@ public class ListPartitionInfo extends PartitionInfo {
// get partition key
PartitionKeyDesc partitionKeyDesc = desc.getPartitionKeyDesc();
if (!partitionKeyDesc.hasInValues()) {
throw new DdlException("List partition expected 'VALUES [IN or ((\"xxx\", \"xxx\"), ...)]'");
}
// we might receive one whole empty values list, we should add default partition value for
// such occasion
for (List<PartitionValue> values : partitionKeyDesc.getInValues()) {

View File

@ -68,6 +68,9 @@ public class RangePartitionInfo extends PartitionInfo {
Range<PartitionKey> newRange = null;
PartitionKeyDesc partitionKeyDesc = desc.getPartitionKeyDesc();
// check range
if (partitionKeyDesc.hasInValues()) {
throw new DdlException("Range partition expected 'VALUES [LESS THAN or [(\"xxx\" ,...), (\"xxx\", ...))]'");
}
try {
newRange = createAndCheckNewRange(partitionKeyDesc, isTemp);
} catch (AnalysisException e) {

View File

@ -0,0 +1,48 @@
// 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_partition_add_mismatched") {
sql "drop table if exists test_partition_add_mismatched_list_tbl"
sql """
CREATE TABLE IF NOT EXISTS test_partition_add_mismatched_list_tbl (
k1 int NOT NULL,
k2 bigint NOT NULL
)
PARTITION BY LIST(k1,k2) ()
DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1")
"""
sql "drop table if exists test_partition_add_mismatched_range_tbl"
sql """
CREATE TABLE IF NOT EXISTS test_partition_add_mismatched_range_tbl (
k1 int NOT NULL,
k2 bigint NOT NULL
)
PARTITION BY RANGE(k1,k2) ()
DISTRIBUTED BY HASH(k1) BUCKETS 5 properties("replication_num" = "1")
"""
test{
sql """ alter table test_partition_add_mismatched_list_tbl add partition p0 values [("0"), ("2")) """
exception "List partition expected 'VALUES [IN or ((\"xxx\", \"xxx\"), ...)]'"
}
test{
sql """ alter table test_partition_add_mismatched_range_tbl add partition p0 values in (("0", "2")) """
exception "Range partition expected 'VALUES [LESS THAN or [(\"xxx\" ,...), (\"xxx\", ...))]'"
}
}