diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionKeyDesc.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionKeyDesc.java index 4cd879535723d0..223576a52c23ba 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionKeyDesc.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/PartitionKeyDesc.java @@ -144,6 +144,10 @@ public PartitionKeyValueType getPartitionType() { return partitionKeyValueType; } + public boolean hasInValues() { + return inValues != null; + } + public void analyze(int partColNum) throws AnalysisException { if (isDummy()) { return; diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionInfo.java index 9d6fb63b26954b..3134d7d3b3f9b2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ListPartitionInfo.java @@ -81,6 +81,10 @@ public PartitionItem createAndCheckPartitionItem(SinglePartitionDesc desc, boole // 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 values : partitionKeyDesc.getInValues()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/RangePartitionInfo.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/RangePartitionInfo.java index 6378a8d6c00fa3..f4d7ac631edaff 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/RangePartitionInfo.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/RangePartitionInfo.java @@ -86,6 +86,9 @@ public PartitionItem createAndCheckPartitionItem(SinglePartitionDesc desc, boole Range 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) { diff --git a/regression-test/suites/partition_p0/test_partition_add_mismatched.groovy b/regression-test/suites/partition_p0/test_partition_add_mismatched.groovy new file mode 100644 index 00000000000000..e9182b9fab6cb9 --- /dev/null +++ b/regression-test/suites/partition_p0/test_partition_add_mismatched.groovy @@ -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\", ...))]'" + } +}