[fix](fe)havingClause should be substituted the same way as resultExprs (#19261)

substituted havingClause in the same way as resultExprs to prevent " HAVING clause not produced by aggregation output" error
This commit is contained in:
starocean999
2023-05-05 18:03:43 +08:00
committed by GitHub
parent 58cb404661
commit 3e3262361c
3 changed files with 10 additions and 2 deletions

View File

@ -1341,9 +1341,13 @@ public class SelectStmt extends QueryStmt {
countAllMap = ExprSubstitutionMap.compose(multiDistinctAggMap, countAllMap, analyzer);
List<Expr> substitutedAggs =
Expr.substituteList(aggExprs, countAllMap, analyzer, false);
// the resultExprs must substitute in the same way as aggExprs
// then resultExprs can be substitute correctly using combinedSmap
// the resultExprs and havingClause must substitute in the same way as aggExprs
// then resultExprs and havingClause can be substitute correctly using combinedSmap
resultExprs = Expr.substituteList(resultExprs, countAllMap, analyzer, false);
if (havingClauseAfterAnaylzed != null) {
havingClauseAfterAnaylzed =
havingClauseAfterAnaylzed.substitute(countAllMap, analyzer, false);
}
aggExprs.clear();
TreeNode.collect(substitutedAggs, Expr.isAggregatePredicate(), aggExprs);