[FIX](agg)fix group by constant child expr bug (#13485)
This commit is contained in:
@ -93,20 +93,12 @@ public class GroupByClause implements ParseNode {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
groupingExprs = new ArrayList<>();
|
||||
analyzed = false;
|
||||
exprGenerated = false;
|
||||
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 (oriGroupingExprs != null) {
|
||||
Expr.resetList(oriGroupingExprs);
|
||||
groupingExprs.addAll(oriGroupingExprs);
|
||||
}
|
||||
if (groupingSetList != null) {
|
||||
for (List<Expr> s : groupingSetList) {
|
||||
|
||||
@ -1389,7 +1389,19 @@ public class SelectStmt extends QueryStmt {
|
||||
}
|
||||
List<Expr> oriGroupingExprs = groupByClause.getOriGroupingExprs();
|
||||
if (oriGroupingExprs != null) {
|
||||
// we must make sure the expr is analyzed before rewrite
|
||||
try {
|
||||
for (Expr expr : oriGroupingExprs) {
|
||||
expr.analyze(analyzer);
|
||||
}
|
||||
} catch (AnalysisException ex) {
|
||||
//ignore any exception
|
||||
}
|
||||
rewriter.rewriteList(oriGroupingExprs, analyzer);
|
||||
// after rewrite, need reset the analyze status for later re-analyze
|
||||
for (Expr expr : oriGroupingExprs) {
|
||||
expr.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (orderByElements != null) {
|
||||
|
||||
@ -2,3 +2,6 @@
|
||||
-- !sql --
|
||||
D
|
||||
|
||||
-- !sql --
|
||||
D
|
||||
|
||||
|
||||
@ -57,6 +57,20 @@ suite("test_group_by_constant") {
|
||||
end;
|
||||
"""
|
||||
|
||||
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 val
|
||||
from
|
||||
table_group_by_constant
|
||||
group by
|
||||
val;
|
||||
"""
|
||||
|
||||
sql """
|
||||
DROP TABLE IF EXISTS `table_group_by_constant`;
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user