LiBinfeng-01 commented on code in PR #40745:
URL: https://github.com/apache/doris/pull/40745#discussion_r1774359267


##########
fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java:
##########
@@ -179,6 +184,70 @@ void testCastFold() {
         Assertions.assertEquals(rewritten, expected);
     }
 
+    @Test
+    void testFoldDate() {
+        executor = new ExpressionRuleExecutor(ImmutableList.of(
+            bottomUp(FoldConstantRuleOnFE.VISITOR_INSTANCE)
+        ));
+        HoursAdd hoursAdd = new 
HoursAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(1));
+        Expression rewritten = executor.rewrite(hoursAdd, context);
+        Assertions.assertTrue(new DateTimeLiteral("0001-01-01 
01:00:00").compareTo((Literal) rewritten) == 0);
+        hoursAdd = new 
HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(1));
+        rewritten = executor.rewrite(hoursAdd, context);
+        Assertions.assertTrue(new DateTimeV2Literal("0001-01-01 
01:00:00").compareTo((Literal) rewritten) == 0);
+        hoursAdd = new 
HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(Integer.MAX_VALUE));
+        rewritten = executor.rewrite(hoursAdd, context);
+        Assertions.assertTrue(new NullLiteral().compareTo((Literal) rewritten) 
== 0);
+        hoursAdd = new 
HoursAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(-25));
+        rewritten = executor.rewrite(hoursAdd, context);
+        Assertions.assertTrue(new NullLiteral().compareTo((Literal) rewritten) 
== 0);
+
+        MinutesAdd minutesAdd = new 
MinutesAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(1));
+        rewritten = executor.rewrite(minutesAdd, context);
+        Assertions.assertTrue(new DateTimeLiteral("0001-01-01 
00:01:00").compareTo((Literal) rewritten) == 0);
+        minutesAdd = new 
MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(1));
+        rewritten = executor.rewrite(minutesAdd, context);
+        Assertions.assertTrue(new DateTimeV2Literal("0001-01-01 
00:01:00").compareTo((Literal) rewritten) == 0);
+        minutesAdd = new 
MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+                new IntegerLiteral(Integer.MAX_VALUE));
+        rewritten = executor.rewrite(minutesAdd, context);
+        Assertions.assertTrue(new DateTimeV2Literal("4084-01-24 
02:07:00").compareTo((Literal) rewritten) == 0);
+        minutesAdd = new 
MinutesAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 0, 1, 1)),
+                new IntegerLiteral(-2));
+        rewritten = executor.rewrite(minutesAdd, context);

Review Comment:
   done



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

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

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