Skip to content

Commit

Permalink
[Fix](planner) legacy planner repeat group by has grouping report err…
Browse files Browse the repository at this point in the history
…or (apache#40281) (apache#40306)

cherry-pick from master apache#40281
  • Loading branch information
feiniaofeiafei authored Sep 4, 2024
1 parent abd9ae2 commit b97e043
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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`)")
}

}

0 comments on commit b97e043

Please sign in to comment.