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

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


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new db06c678a3d [Fix](planner) legacy planner repeat group by has grouping 
report error (#40281) (#40305)
db06c678a3d is described below

commit db06c678a3d11f636c8b5c49ca9f050228863742
Author: feiniaofeiafei <[email protected]>
AuthorDate: Wed Sep 4 08:50:21 2024 +0800

    [Fix](planner) legacy planner repeat group by has grouping report error 
(#40281) (#40305)
    
    cherry-pick #40281 to branch-2.1
---
 .../org/apache/doris/analysis/GroupByClause.java   |  5 +++
 .../grouping_sets/valid_grouping.groovy            | 51 ++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
index f6305e611da..9b505594467 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/GroupByClause.java
@@ -192,6 +192,11 @@ public class GroupByClause implements ParseNode {
                         "GROUP BY expression must not contain aggregate 
functions: "
                                 + groupingExpr.toSql());
             }
+            if (groupingExpr.contains(GroupingFunctionCallExpr.class)) {
+                throw new AnalysisException(
+                        "GROUP BY expression must not contain grouping scalar 
functions: "
+                                + groupingExpr.toSql());
+            }
             if (groupingExpr.contains(AnalyticExpr.class)) {
                 // reference the original expr in the error msg
                 throw new AnalysisException(
diff --git 
a/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy 
b/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy
new file mode 100644
index 00000000000..dd69f23f027
--- /dev/null
+++ 
b/regression-test/suites/nereids_rules_p0/grouping_sets/valid_grouping.groovy
@@ -0,0 +1,51 @@
+// 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("valid_grouping"){
+    sql "SET enable_fallback_to_original_planner=true"
+    sql "drop table if exists valid_grouping"
+    sql """
+    CREATE TABLE `valid_grouping` (
+      `a` INT NULL,
+      `b` VARCHAR(10) NULL,
+      `c` INT NULL,
+      `d` INT NULL
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`a`, `b`)
+    DISTRIBUTED BY RANDOM BUCKETS AUTO
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1"
+    );
+    """
+    sql "insert into valid_grouping values(1,'d2',3,5);"
+    test {
+        sql """select
+        b, 'day' as DT_TYPE
+        from valid_grouping
+        group by grouping sets ( (grouping_id(b)),(b));"""
+        exception("GROUP BY expression must not contain grouping scalar 
functions: grouping_id(`b`)")
+    }
+
+    test {
+        sql """select
+        b, 'day' as DT_TYPE
+        from valid_grouping
+        group by grouping sets ( (grouping(b)),(b));"""
+        exception("GROUP BY expression must not contain grouping scalar 
functions: grouping(`b`)")
+    }
+
+}
\ No newline at end of file


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

Reply via email to