You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/04/30 02:17:08 UTC

[GitHub] [incubator-doris] wangbo commented on a change in pull request #3396: (#3395)calculate 'case when expr' when possible

wangbo commented on a change in pull request #3396:
URL: https://github.com/apache/incubator-doris/pull/3396#discussion_r417717067



##########
File path: fe/src/test/java/org/apache/doris/planner/QueryPlanTest.java
##########
@@ -504,4 +504,106 @@ public void testDateTypeEquality() throws Exception {
         Catalog.getCurrentCatalog().getLoadManager().createLoadJobV1FromStmt(loadStmt, EtlJobType.HADOOP,
                 System.currentTimeMillis());
     }
+
+    private SelectStmt getAnalyzedAndRewritedStmt(String sql) throws Exception {
+        SelectStmt selectStmt =
+                (SelectStmt) UtFrameUtils.parseAndAnalyzeStmt(sql, connectContext);
+        selectStmt = (SelectStmt) UtFrameUtils.rewriteStmt(selectStmt, connectContext);
+        selectStmt = (SelectStmt) UtFrameUtils.reAnalyze(selectStmt, connectContext);
+        return selectStmt;
+    }
+
+    @Test
+    public void testConvertCaseWhenToConstant() throws Exception {
+        // basic test
+        String caseWhenSql = "select "
+                + "case when date_format(now(),'%H%i')  < 123 then 1 else 0 end as col "
+                + "from test.test1 "
+                + "where time = case when date_format(now(),'%H%i')  < 123 then date_format(date_sub(now(),2),'%Y%m%d') else date_format(date_sub(now(),1),'%Y%m%d') end";
+        SelectStmt selectStmt = getAnalyzedAndRewritedStmt(caseWhenSql);
+        Assert.assertTrue(!selectStmt.toSql().contains("CASE WHEN") && !selectStmt.toSql().contains("case when"));

Review comment:
       👌




----------------------------------------------------------------
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:
users@infra.apache.org



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