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

yiguolei 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 a4a991207b [fix](agg)fix group by constant value bug (#13827)
a4a991207b is described below

commit a4a991207bd481bb3bb96921e85532eaf40633bd
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Thu Nov 3 10:26:59 2022 +0800

    [fix](agg)fix group by constant value bug (#13827)
    
    * [fix](agg)fix group by constant value bug
    
    * keep only one const grouping exprs if no agg exprs
---
 .../java/org/apache/doris/analysis/SelectStmt.java |  7 ++++++-
 .../sql/group_by/runConstantGroupBy_order.out      | 24 ----------------------
 2 files changed, 6 insertions(+), 25 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 f522dcd898..55aebf9280 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
@@ -1092,8 +1092,13 @@ public class SelectStmt extends QueryStmt {
 
             substituteOrdinalsAliases(groupingExprs, "GROUP BY", analyzer);
 
-            if (!groupByClause.isGroupByExtension()) {
+            if (!groupByClause.isGroupByExtension() && 
!groupingExprs.isEmpty()) {
+                ArrayList<Expr> tempExprs = new ArrayList<>(groupingExprs);
                 groupingExprs.removeIf(Expr::isConstant);
+                if (groupingExprs.isEmpty() && aggExprs.isEmpty()) {
+                    // should keep at least one expr to make the result correct
+                    groupingExprs.add(tempExprs.get(0));
+                }
             }
 
             if (groupingInfo != null) {
diff --git 
a/regression-test/data/trino_p0/sql/group_by/runConstantGroupBy_order.out 
b/regression-test/data/trino_p0/sql/group_by/runConstantGroupBy_order.out
index 3e7855ddba..6a880dbc0a 100644
--- a/regression-test/data/trino_p0/sql/group_by/runConstantGroupBy_order.out
+++ b/regression-test/data/trino_p0/sql/group_by/runConstantGroupBy_order.out
@@ -1,28 +1,4 @@
 -- This file is automatically generated. You should know what you did if you 
want to edit this
 -- !runConstantGroupBy_order --
 2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
-2
 


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

Reply via email to