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

zhangstar333 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 57226bce947 [Fix](show-stmt) Raise an error when show partitions with 
complex predicate  (#45257)
57226bce947 is described below

commit 57226bce94712a8e34798da8af7e1f46a7435b51
Author: zclllyybb <zhaochan...@selectdb.com>
AuthorDate: Tue Dec 17 15:19:51 2024 +0800

    [Fix](show-stmt) Raise an error when show partitions with complex predicate 
 (#45257)
    
    ### What problem does this PR solve?
    we support `partitions` tvf. so it's not necessary to support this.
    raise an error.
    Co-authored-by: Pxl <x...@selectdb.com>
---
 .../doris/common/proc/PartitionsProcDir.java       |  9 ++++-
 .../query_p0/show/test_show_partitions.groovy      | 39 ++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java 
b/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java
index c76a4185fca..3fd945c013c 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/common/proc/PartitionsProcDir.java
@@ -22,6 +22,7 @@ import org.apache.doris.analysis.DateLiteral;
 import org.apache.doris.analysis.Expr;
 import org.apache.doris.analysis.IntLiteral;
 import org.apache.doris.analysis.LimitElement;
+import org.apache.doris.analysis.LiteralExpr;
 import org.apache.doris.analysis.StringLiteral;
 import org.apache.doris.catalog.Column;
 import org.apache.doris.catalog.DataProperty;
@@ -94,11 +95,16 @@ public class PartitionsProcDir implements ProcDirInterface {
         if (filterMap == null) {
             return true;
         }
-        Expr subExpr = filterMap.get(columnName.toLowerCase());
+        Expr subExpr = filterMap.get(columnName.toLowerCase()); // predicate 
on this column.
         if (subExpr == null) {
             return true;
         }
         if (subExpr instanceof BinaryPredicate) {
+            // show partitions only provide very limited filtering capacity in 
FE. so restrict here.
+            if (!(subExpr.getChild(1) instanceof LiteralExpr)) {
+                throw new AnalysisException("Not Supported. Use `select * from 
partitions(...)` instead");
+            }
+
             BinaryPredicate binaryPredicate = (BinaryPredicate) subExpr;
             if (subExpr.getChild(1) instanceof StringLiteral
                     && binaryPredicate.getOp() == BinaryPredicate.Operator.EQ) 
{
@@ -169,6 +175,7 @@ public class PartitionsProcDir implements ProcDirInterface {
             filterPartitionInfos = partitionInfos;
         } else {
             filterPartitionInfos = Lists.newArrayList();
+            // TODO: we should change the order of loops to speed up. use 
filters to filter column value.
             for (List<Comparable> partitionInfo : partitionInfos) {
                 if (partitionInfo.size() != TITLE_NAMES.size()) {
                     throw new AnalysisException("PartitionInfos.size() " + 
partitionInfos.size()
diff --git a/regression-test/suites/query_p0/show/test_show_partitions.groovy 
b/regression-test/suites/query_p0/show/test_show_partitions.groovy
new file mode 100644
index 00000000000..bf88872029e
--- /dev/null
+++ b/regression-test/suites/query_p0/show/test_show_partitions.groovy
@@ -0,0 +1,39 @@
+// 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_show_partitions") {
+    sql "drop table if exists test_show_part"
+    sql """
+        create table test_show_part (
+            month varchar (255),
+            id int,
+            code varchar (255),
+            name varchar (255)
+        ) ENGINE = OLAP DUPLICATE KEY(month, id)
+        AUTO PARTITION BY LIST (month)()
+        distributed by hash (id) buckets auto
+        PROPERTIES(
+        "replication_allocation" = "tag.location.default: 1"
+        )
+    """
+    sql """ insert into test_show_part(month, id, code, name) values 
('2024-12', 10001, 'test10001', 'test') """
+    test {
+        sql "show partitions from test_show_part where PartitionName = 
auto_partition_name('list','2024-12')"
+        exception "Not Supported. Use `select * from partitions(...)` instead"
+    }
+    sql " show partitions from test_show_part where PartitionName = '123'; "
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to