This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 4a39b2b338f branch-2.1: [fix](partition) Add partition of mismatched 
type to table #47200 (#48066)
4a39b2b338f is described below

commit 4a39b2b338fdeef8a8345387447ce33a7ba879ff
Author: Uniqueyou <[email protected]>
AuthorDate: Wed Feb 19 19:17:58 2025 +0800

    branch-2.1: [fix](partition) Add partition of mismatched type to table 
#47200 (#48066)
    
    pick: https://github.com/apache/doris/pull/47200
---
 .../apache/doris/analysis/PartitionKeyDesc.java    |  4 ++
 .../apache/doris/catalog/ListPartitionInfo.java    |  4 ++
 .../apache/doris/catalog/RangePartitionInfo.java   |  3 ++
 .../test_partition_add_mismatched.groovy           | 48 ++++++++++++++++++++++
 4 files changed, 59 insertions(+)

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 4cd87953572..223576a52c2 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 class PartitionKeyDesc {
         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 437932497be..8be09e0c31e 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
@@ -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()) {
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 dd0bbff701d..3361755212f 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
@@ -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) {
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 00000000000..e9182b9fab6
--- /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\", ...))]'"
+       }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to