Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -419,23 +419,20 @@ protected void substituteOrdinalsAliases(List<Expr> exprs, String errorPrefix,
// alias substitution is not performed in the same way.
Expr substituteExpr = trySubstituteOrdinal(expr, errorPrefix, analyzer);
if (substituteExpr == null) {
substituteExpr = expr.trySubstitute(aliasSMap, analyzer, false);
if (aliasFirst) {
substituteExpr = expr.trySubstitute(aliasSMap, analyzer, false);
i.set(substituteExpr);
} else {
try {
// use col name from tableRefs first
expr.analyze(analyzer);
substituteExpr = expr.clone();
substituteExpr.analyze(analyzer);
} catch (AnalysisException ex) {
// then consider alias name
substituteExpr = expr.trySubstitute(aliasSMap, analyzer, false);
i.set(substituteExpr);
}
}
} else {
i.set(substituteExpr);
}
i.set(substituteExpr);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,14 @@ private void analyzeAggregation(Analyzer analyzer) throws AnalysisException {
* (select min(k1) from table b where a.key=b.k2);
* TODO: the a.key should be replaced by a.k1 instead of unknown column 'key' in 'a'
*/
havingClauseAfterAnaylzed = havingClause.substitute(aliasSMap, analyzer, false);
try {
// use col name from tableRefs first
havingClauseAfterAnaylzed = havingClause.clone();
havingClauseAfterAnaylzed.analyze(analyzer);
} catch (AnalysisException ex) {
// then consider alias name
havingClauseAfterAnaylzed = havingClause.substitute(aliasSMap, analyzer, false);
}
havingClauseAfterAnaylzed = rewriteQueryExprByMvColumnExpr(havingClauseAfterAnaylzed, analyzer);
havingClauseAfterAnaylzed.checkReturnsBool("HAVING clause", true);
if (groupingInfo != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void testCollectExprs() throws Exception {
stmt = (QueryStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, ctx);
exprsMap.clear();
stmt.collectExprs(exprsMap);
Assert.assertEquals(15, exprsMap.size());
Assert.assertEquals(17, exprsMap.size());
constMap.clear();
constMap = getConstantExprMap(exprsMap, analyzer);
Assert.assertEquals(4, constMap.size());
Expand Down