You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by yi...@apache.org on 2022/12/07 07:29:29 UTC
[doris] branch branch-1.1-lts updated: [fix](agg)having clause should use alias if there is no group by clause (#14874)
This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-1.1-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.1-lts by this push:
new a1728f19d4 [fix](agg)having clause should use alias if there is no group by clause (#14874)
a1728f19d4 is described below
commit a1728f19d413ff51273cee3e886afe5504aaef33
Author: starocean999 <40...@users.noreply.github.com>
AuthorDate: Wed Dec 7 15:29:22 2022 +0800
[fix](agg)having clause should use alias if there is no group by clause (#14874)
---
.../java/org/apache/doris/analysis/SelectStmt.java | 21 +++++++++++++++------
1 file changed, 15 insertions(+), 6 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 63121fb3db..7bf212f84d 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -969,12 +969,21 @@ public class SelectStmt extends QueryStmt {
* (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'
*/
- try {
- // use col name from tableRefs first
- havingClauseAfterAnaylzed = havingClause.clone();
- havingClauseAfterAnaylzed.analyze(analyzer);
- } catch (AnalysisException ex) {
- // then consider alias name
+ if (groupByClause != null) {
+ // according to mysql
+ // if there is a group by clause, the having clause should use column name not alias
+ // this is the same as group by clause
+ 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);
+ }
+ } else {
+ // according to mysql
+ // if there is no group by clause, the having clause should use alias
havingClauseAfterAnaylzed = havingClause.substitute(aliasSMap, analyzer, false);
}
havingClauseAfterAnaylzed = rewriteQueryExprByMvColumnExpr(havingClauseAfterAnaylzed, analyzer);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org