Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,9 @@ private void analyzeAggregation(Analyzer analyzer) throws AnalysisException {
countAllMap = ExprSubstitutionMap.compose(multiCountOrSumDistinctMap, 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
resultExprs = Expr.substituteList(resultExprs, countAllMap, analyzer, false);
aggExprs.clear();
TreeNode.collect(substitutedAggs, Expr.isAggregatePredicate(), aggExprs);

Expand Down Expand Up @@ -1395,29 +1398,42 @@ public void rewriteExprs(ExprRewriter rewriter) throws AnalysisException {
// we must make sure the expr is analyzed before rewrite
try {
for (Expr expr : oriGroupingExprs) {
expr.analyze(analyzer);
if (!(expr instanceof SlotRef)) {
// if group expr is not a slotRef, it should be analyzed in the same way as result expr
// otherwise, the group expr is either a simple column or an alias, no need to analyze
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 (!(expr instanceof SlotRef)) {
expr.reset();
}
}
}
}
if (orderByElements != null) {
for (OrderByElement orderByElem : orderByElements) {
// we must make sure the expr is analyzed before rewrite
try {
orderByElem.getExpr().analyze(analyzer);
if (!(orderByElem.getExpr() instanceof SlotRef)) {
// if sort expr is not a slotRef, it should be analyzed in the same way as result expr
// otherwise, the sort expr is either a simple column or an alias, no need to analyze
orderByElem.getExpr().analyze(analyzer);
}
} catch (AnalysisException ex) {
//ignore any exception
}
orderByElem.setExpr(rewriter.rewrite(orderByElem.getExpr(), analyzer));
// after rewrite, need reset the analyze status for later re-analyze
orderByElem.getExpr().reset();
if (!(orderByElem.getExpr() instanceof SlotRef)) {
orderByElem.getExpr().reset();
}
}
}
}
Expand Down