EmmyMiao87 commented on a change in pull request #3135: support subquery in 
case when statement
URL: https://github.com/apache/incubator-doris/pull/3135#discussion_r394779004
 
 

 ##########
 File path: fe/src/main/java/org/apache/doris/analysis/SelectStmt.java
 ##########
 @@ -1246,6 +1228,68 @@ public void rewriteExprs(ExprRewriter rewriter) throws 
AnalysisException {
         }
     }
 
+    /** rewrite subquery in case when to an inline view
+     *  subquery in case when statement like
+     *
+     * SELECT CASE
+     *         WHEN (
+     *             SELECT COUNT(*) / 2
+     *             FROM t
+     *         ) > k4 THEN (
+     *             SELECT AVG(k4)
+     *             FROM t
+     *         )
+     *         ELSE (
+     *             SELECT SUM(k4)
+     *             FROM t
+     *         )
+     *     END AS kk4
+     * FROM t;
+     * this statement will be rewrite to
+     *
+     * SELECT CASE
+     *         WHEN t1.a > k4 THEN t2.a
+     *         ELSE t3.a
+     *     END AS kk4
+     * FROM t, (
+     *         SELECT COUNT(*) / 2 AS a
+     *         FROM t
+     *     ) t1,  (
+     *         SELECT AVG(k4) AS a
+     *         FROM t
+     *     ) t2,  (
+     *         SELECT SUM(k4) AS a
+     *         FROM t
+     *     ) t3;
+     */
+    private Expr rewriteSubquery(Expr expr) throws AnalysisException {
 
 Review comment:
   The entire query should be reanalyzed if there is subquery is rewritten. So 
maybe this method should be move to StmtRewriter.

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