morningman 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_r396195732
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/BinaryPredicate.java
 ##########
 @@ -313,14 +314,30 @@ public void analyzeImpl(Analyzer analyzer) throws 
AnalysisException {
         super.analyzeImpl(analyzer);
 
         for (Expr expr : children) {
-            if (expr instanceof Subquery && !((Subquery) 
expr).returnsScalarColumn()) {
-                String msg = "Subquery of binary predicate must return a 
single column: " + expr.toSql();
-                throw new AnalysisException(msg);
+            if (expr instanceof Subquery) {
+                Subquery subquery = (Subquery) expr;
+                if (!subquery.returnsScalarColumn()) {
+                    String msg = "Subquery of binary predicate must return a 
single column: " + expr.toSql();
+                    throw new AnalysisException(msg);
+                }
+                /**
+                 * Situation: The expr is a binary predicate and the type of 
subquery is not scalar type.
+                 * Add assert: The stmt of subquery is added an assert 
condition (return error if row count > 1).
+                 * Input params:
+                 *     expr: k1=(select k1 from t2)
+                 *     subquery stmt: select k1 from t2
+                 * Output params:
+                 *     new expr: k1 = (select k1 from t2 (assert row count: 
return error if row count > 1 ))
+                 *     subquery stmt: select k1 from t2 (assert row count: 
return error if row count > 1 )
+                 */
+                if (!subquery.getType().isScalarType()) {
+                    subquery.getStatement().setAssertNumRowsElement(1);
+                }
             }
         }
 
         // if children has subquery, it will be written and reanalyzed in the 
future.
 
 Review comment:
   ```suggestion
           // if children has subquery, it will be rewritten and reanalyzed in 
the future.
   ```

----------------------------------------------------------------
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