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

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


The following commit(s) were added to refs/heads/branch-2.0 by this push:
     new 3a65e98003d [fix](legacy-planner) fixed loss of BetweenPredicate 
rewrite on reanalyze in legacy planner (#31454)
3a65e98003d is described below

commit 3a65e98003d97f711ad9c43bb3b9f7f96e07cce9
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Tue Feb 27 16:10:37 2024 +0800

    [fix](legacy-planner) fixed loss of BetweenPredicate rewrite on reanalyze 
in legacy planner (#31454)
---
 .../java/org/apache/doris/analysis/SelectStmt.java |  1 +
 .../data/query_p0/having/having_between.out        | 31 ++++++++++
 .../suites/query_p0/having/having_between.groovy   | 72 ++++++++++++++++++++++
 3 files changed, 104 insertions(+)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 967ceb4b272..344fa3df6db 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -1862,6 +1862,7 @@ public class SelectStmt extends QueryStmt {
         if (havingClauseAfterAnalyzed != null) {
             havingClauseAfterAnalyzed = 
rewriter.rewrite(havingClauseAfterAnalyzed, analyzer);
             havingClauseAfterAnalyzed.collect(Subquery.class, subqueryExprs);
+            havingClause = havingClauseAfterAnalyzed.clone();
         }
 
         for (Subquery subquery : subqueryExprs) {
diff --git a/regression-test/data/query_p0/having/having_between.out 
b/regression-test/data/query_p0/having/having_between.out
new file mode 100644
index 00000000000..d8adf194fd7
--- /dev/null
+++ b/regression-test/data/query_p0/having/having_between.out
@@ -0,0 +1,31 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql01 --
+aa     ba      22      cc      11      \N
+b      b       242     c       121     \N
+bb     b       22      c       11      \N
+
+-- !sql02 --
+aa     1
+b      1
+bb     1
+
+-- !sql03 --
+aa     1
+b      1
+bb     1
+
+-- !sql01 --
+aa     ba      22      cc      11      \N
+b      b       242     c       121     \N
+bb     b       22      c       11      \N
+
+-- !sql02 --
+aa     1
+b      1
+bb     1
+
+-- !sql03 --
+aa     1
+b      1
+bb     1
+
diff --git a/regression-test/suites/query_p0/having/having_between.groovy 
b/regression-test/suites/query_p0/having/having_between.groovy
new file mode 100644
index 00000000000..7f3091795b6
--- /dev/null
+++ b/regression-test/suites/query_p0/having/having_between.groovy
@@ -0,0 +1,72 @@
+// 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_having_between", "query,p0") {
+    def DBname = "test_having_between"
+    def tableName = "tbl_having_between"
+    sql "DROP DATABASE IF EXISTS ${DBname}"
+    sql "CREATE DATABASE IF NOT EXISTS ${DBname}"
+    sql "use ${DBname}"
+
+    sql "DROP TABLE IF EXISTS ${tableName};"
+
+    sql """
+        CREATE TABLE ${tableName}(a DATE, b VARCHAR(100), c VARCHAR(100), d 
VARCHAR(100), e INT, f INT)  
+        ENGINE=OLAP
+        DUPLICATE KEY( a )
+        COMMENT "OLAP"
+        DISTRIBUTED BY HASH( e ) BUCKETS  auto
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+    """
+
+    def test_query = {
+        qt_sql01 """
+            select t1.b,t1.c,t1.f,t1.d,t1.e,stddev_pop(t1.d+t1.e) std from 
${tableName} t1 
+            group by t1.f,t1.d,t1.e,t1.a,t1.b,t1.c
+            having t1.b between 'aa' and 'bb' order by 1;
+        """
+
+        qt_sql02 """
+            SELECT b, count(*) FROM ${tableName} GROUP BY 1 HAVING b BETWEEN 
'aa' AND 'bb' order by 1;
+        """
+
+        qt_sql03 """
+            SELECT b, count(*) FROM ${tableName} GROUP BY 1 HAVING b >= 'aa' 
AND b <= 'bb' order by 1;
+        """
+    }
+
+    sql "INSERT INTO ${tableName} VALUES(now(), 'a', 'b', 'c', 11, 22);"
+    sql "INSERT INTO ${tableName} VALUES(now(), 'aa', 'ba', 'cc', 11, 22);"
+    sql "INSERT INTO ${tableName} VALUES(now(), 'b', 'b', 'c', 121, 242);"
+    sql "INSERT INTO ${tableName} VALUES(now(), 'bb', 'b', 'c', 11, 22);"
+    sql "INSERT INTO ${tableName} VALUES(now(), 'bbb', 'b', 'c', 11, 22);"
+
+    sql """set enable_nereids_planner=true;"""
+    sql "set enable_fallback_to_original_planner=false;"
+
+    // with nereids planner
+    test_query()
+    sql """set enable_nereids_planner=false;"""
+
+    // with legacy planner
+    test_query()
+
+    sql "DROP TABLE ${tableName};"
+    sql "DROP DATABASE ${DBname};"
+}
\ 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