[fix](agg) reset the content of grouping exprs instead of replace it with original exprs (#13376)

* [fix](agg)the reseet the content of grouping exprs instead of replace it with original exprs

* keep old behavior if the grouping type is not GROUP_BY
This commit is contained in:
starocean999
2022-10-15 11:07:35 +08:00
committed by GitHub
parent 52397df9f0
commit bf2e20c4c4
3 changed files with 79 additions and 4 deletions

View File

@ -93,12 +93,20 @@ public class GroupByClause implements ParseNode {
}
public void reset() {
groupingExprs = new ArrayList<>();
analyzed = false;
exprGenerated = false;
if (oriGroupingExprs != null) {
Expr.resetList(oriGroupingExprs);
groupingExprs.addAll(oriGroupingExprs);
if (groupingType != GroupingType.GROUP_BY) {
groupingExprs = new ArrayList<>();
if (oriGroupingExprs != null) {
Expr.resetList(oriGroupingExprs);
groupingExprs.addAll(oriGroupingExprs);
}
} else {
if (groupingExprs != null) {
for (Expr e : groupingExprs) {
e.reset();
}
}
}
if (groupingSetList != null) {
for (List<Expr> s : groupingSetList) {

View File

@ -0,0 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
D

View File

@ -0,0 +1,63 @@
// 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("test_group_by_constant") {
sql """
DROP TABLE IF EXISTS `table_group_by_constant`;
"""
sql """
CREATE TABLE `table_group_by_constant` (
`inc_day` date NULL
) ENGINE=OLAP
UNIQUE KEY(`inc_day`)
DISTRIBUTED BY HASH(`inc_day`) BUCKETS 5
PROPERTIES (
"replication_allocation" = "tag.location.default: 1",
"in_memory" = "false",
"storage_format" = "V2"
);
"""
sql """
insert into table_group_by_constant values('1999-12-01');
"""
qt_sql """
SELECT
case
when (inc_day = date_sub(curdate(), interval 1 day)) then 'A'
when (inc_day = date_sub(curdate(), interval 8 day)) then 'B'
when (inc_day = date_sub(curdate(), interval 365 day)) then 'C'
else 'D'
end
from
table_group_by_constant
group by
case
when (inc_day = date_sub(curdate(), interval 1 day)) then 'A'
when (inc_day = date_sub(curdate(), interval 8 day)) then 'B'
when (inc_day = date_sub(curdate(), interval 365 day)) then 'C'
else 'D'
end;
"""
sql """
DROP TABLE IF EXISTS `table_group_by_constant`;
"""
}