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

morningman pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 9be8263050db9c52337052f82fd3adab8d3488db
Author: starocean999 <[email protected]>
AuthorDate: Fri May 5 18:03:43 2023 +0800

    [fix](fe)havingClause should be substituted the same way as resultExprs 
(#19261)
    
    substituted havingClause in the same way as resultExprs to prevent " HAVING 
clause not produced by aggregation output" error
---
 .../src/main/java/org/apache/doris/analysis/SelectStmt.java       | 8 ++++++--
 regression-test/data/correctness_p0/test_group_having_alias.out   | 3 +++
 .../suites/correctness_p0/test_group_having_alias.groovy          | 3 +++
 3 files changed, 12 insertions(+), 2 deletions(-)

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 5884ea7d0f..9e36a5a51a 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
@@ -1155,9 +1155,13 @@ public class SelectStmt extends QueryStmt {
         countAllMap = ExprSubstitutionMap.compose(multiDistinctAggMap, 
countAllMap, analyzer);
         List<Expr> substitutedAggs =
                 Expr.substituteList(aggExprs, countAllMap, analyzer, false);
-        // the resultExprs must substitute in the same way as aggExprs
-        // then resultExprs can be substitute correctly using combinedSmap
+        // the resultExprs and havingClause must substitute in the same way as 
aggExprs
+        // then resultExprs and havingClause can be substitute correctly using 
combinedSmap
         resultExprs = Expr.substituteList(resultExprs, countAllMap, analyzer, 
false);
+        if (havingClauseAfterAnaylzed != null) {
+            havingClauseAfterAnaylzed =
+                    havingClauseAfterAnaylzed.substitute(countAllMap, 
analyzer, false);
+        }
         aggExprs.clear();
         TreeNode.collect(substitutedAggs, Expr.isAggregatePredicate(), 
aggExprs);
 
diff --git a/regression-test/data/correctness_p0/test_group_having_alias.out 
b/regression-test/data/correctness_p0/test_group_having_alias.out
index 1c4feeeecb..4ba36af336 100644
--- a/regression-test/data/correctness_p0/test_group_having_alias.out
+++ b/regression-test/data/correctness_p0/test_group_having_alias.out
@@ -36,3 +36,6 @@
 -- !case5 --
 2      3
 
+-- !case_cir2273 --
+2.5
+
diff --git 
a/regression-test/suites/correctness_p0/test_group_having_alias.groovy 
b/regression-test/suites/correctness_p0/test_group_having_alias.groovy
index 8429be8920..c74fe96420 100644
--- a/regression-test/suites/correctness_p0/test_group_having_alias.groovy
+++ b/regression-test/suites/correctness_p0/test_group_having_alias.groovy
@@ -133,5 +133,8 @@
     qt_case3 """ SELECT id, v1-2 as v, sum(v2) v2 FROM test_having_alias_tb 
GROUP BY id,v having(v>0 AND sum(v2)>1) ORDER BY id,v; """
     qt_case4 """ SELECT id, v1-2 as v, sum(v2) vsum FROM test_having_alias_tb 
GROUP BY id,v having(v>0 AND vsum>1) ORDER BY id,v; """
     qt_case5 """ SELECT id, max(v1) v1 FROM test_having_alias_tb GROUP BY 1 
having count(distinct v1)>1 ORDER BY id; """
+    qt_case_cir2273 """ select sum( id * 0.5 ) val from test_having_alias_tb 
having val > 0; """
+
     sql """ DROP TABLE IF EXISTS `test_having_alias_tb`; """
  } 
+


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

Reply via email to