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



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

Reply via email to