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

yiguolei pushed a commit to branch dev-1.1.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/dev-1.1.2 by this push:
     new 6f0d0b6867 [fix](agg)grouping_id function in having is not correctly 
substituted (#11834)
6f0d0b6867 is described below

commit 6f0d0b68674bfe5e4c87f46161ede97ad8ed380f
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Wed Aug 24 08:50:28 2022 +0800

    [fix](agg)grouping_id function in having is not correctly substituted 
(#11834)
---
 .../java/org/apache/doris/analysis/SelectStmt.java |  3 ++
 .../query/aggregate/aggregate_having_grouping.out  |  9 ++++
 .../aggregate/aggregate_having_grouping.groovy     | 56 ++++++++++++++++++++++
 3 files changed, 68 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 f6fba9b9be..54734359c3 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
@@ -960,6 +960,9 @@ public class SelectStmt extends QueryStmt {
             havingClauseAfterAnaylzed = havingClause.substitute(aliasSMap, 
analyzer, false);
             havingClauseAfterAnaylzed = 
rewriteQueryExprByMvColumnExpr(havingClauseAfterAnaylzed, analyzer);
             havingClauseAfterAnaylzed.checkReturnsBool("HAVING clause", true);
+            if (groupingInfo != null) {
+                
groupingInfo.substituteGroupingFn(Arrays.asList(havingClauseAfterAnaylzed), 
analyzer);
+            }
             // can't contain analytic exprs
             Expr analyticExpr = 
havingClauseAfterAnaylzed.findFirstOf(AnalyticExpr.class);
             if (analyticExpr != null) {
diff --git a/regression-test/data/query/aggregate/aggregate_having_grouping.out 
b/regression-test/data/query/aggregate/aggregate_having_grouping.out
new file mode 100644
index 0000000000..ab97ec396d
--- /dev/null
+++ b/regression-test/data/query/aggregate/aggregate_having_grouping.out
@@ -0,0 +1,9 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !select --
+1      3       6
+1      3       6
+1      3       6
+2      3       6
+2      3       6
+2      3       6
+
diff --git 
a/regression-test/suites/query/aggregate/aggregate_having_grouping.groovy 
b/regression-test/suites/query/aggregate/aggregate_having_grouping.groovy
new file mode 100644
index 0000000000..90a066b3a8
--- /dev/null
+++ b/regression-test/suites/query/aggregate/aggregate_having_grouping.groovy
@@ -0,0 +1,56 @@
+// 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("aggregate_having_grouping") {
+    sql "DROP TABLE IF EXISTS test_aggregate_having_grouping"
+
+    sql """
+        CREATE TABLE test_aggregate_having_grouping (
+        `dt_date` varchar(1000) NULL COMMENT "",
+        `name` varchar(1000) NULL COMMENT "",
+        `num1` bigint(20) SUM NOT NULL COMMENT "",
+        `num2` bigint(20) SUM NOT NULL COMMENT ""
+        ) ENGINE=OLAP
+        AGGREGATE KEY(`dt_date`, `name`)
+        COMMENT "OLAP"
+        DISTRIBUTED BY HASH(`dt_date`) BUCKETS 32
+        PROPERTIES (
+        "replication_allocation" = "tag.location.default: 1",
+        "in_memory" = "false",
+        "storage_format" = "V2"
+        )
+        """
+
+    sql """INSERT INTO test_aggregate_having_grouping values ('2022-08-01', 
"aaa", 1,2),('2022-08-01', "bbb", 1,2),
+            ('2022-08-01', "ccc", 1,2),('2022-08-02', "aaa", 
1,2),('2022-08-02', "bbb", 1,2),
+            ('2022-08-02', "ccc", 1,2),('2022-08-03', "aaa", 
1,2),('2022-08-03', "bbb", 1,2),
+            ('2022-08-03', "ccc", 1,2);"""
+
+    qt_select """ SELECT grouping_id(dt_date,name) grouping,sum(num1), 
sum(num2)
+                FROM test_aggregate_having_grouping
+                GROUP BY grouping sets
+                (
+                (dt_date),
+                (name),
+                (dt_date,name)
+                )
+                HAVING grouping!=0
+                order by grouping;
+            """
+
+    sql "DROP TABLE test_aggregate_having_grouping"
+}
\ 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