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 f6305e611da442..9b5055944674b2 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 void analyze(Analyzer analyzer) throws AnalysisException { "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 00000000000000..dd69f23f027f21 --- /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