wutiangan commented on a change in pull request #3150: Support non-correlated 
subquery in having clause
URL: https://github.com/apache/incubator-doris/pull/3150#discussion_r397250060
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
 ##########
 @@ -839,19 +861,32 @@ private Expr rewriteCountDistinctForBitmapOrHLL(Expr 
expr, Analyzer analyzer) {
     private void analyzeAggregation(Analyzer analyzer) throws 
AnalysisException {
         // check having clause
         if (havingClause != null) {
-            if (havingClause.contains(Predicates.instanceOf(Subquery.class))) {
-                throw new AnalysisException(
-                        "Subqueries are not supported in the HAVING clause.");
-            }
             Expr ambiguousAlias = getFirstAmbiguousAlias(havingClause);
             if (ambiguousAlias != null) {
                 
ErrorReport.reportAnalysisException(ErrorCode.ERR_NON_UNIQ_ERROR, 
ambiguousAlias.toColumnLabel());
             }
-            // substitute aliases in place (ordinals not allowed in having 
clause)
-            havingPred = havingClause.substitute(aliasSMap, analyzer, false);
-            havingPred.checkReturnsBool("HAVING clause", true);
+            /*
+             * The having clause need to be substitute by aliasSMap.
+             * And it is analyzed after substitute.
+             * For example:
+             * Query: select k1 a, sum(k2) b from table group by k1 having a > 
1;
+             * Having clause: a > 1
+             * aliasSMap: <a, table.k1> <b, sum(table.k2)>
+             * After substitute: a > 1 changed to table.k1 > 1
+             * Analyzer: check column and other subquery in having clause
+             * having predicate: table.k1 > 1
+             */
+            /*
+             * TODO(ml): support substitute outer column in subquery
 
 Review comment:
   ```suggestion
                * TODO(ml): support substitute outer column in correlated 
subquery
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to