LiBinfeng-01 commented on code in PR #40745:
URL: https://github.com/apache/doris/pull/40745#discussion_r1774360359
##########
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);
+ Assertions.assertTrue(new NullLiteral().compareTo((Literal) rewritten)
== 0);
+
+ SecondsAdd secondsAdd = new
SecondsAdd(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+ new IntegerLiteral(1));
+ rewritten = executor.rewrite(secondsAdd, context);
+ Assertions.assertTrue(new DateTimeLiteral("0001-01-01
00:00:01").compareTo((Literal) rewritten) == 0);
+ secondsAdd = new
SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)),
+ new IntegerLiteral(1));
+ rewritten = executor.rewrite(secondsAdd, context);
+ Assertions.assertTrue(new DateTimeV2Literal("0001-01-01
00:00:01").compareTo((Literal) rewritten) == 0);
Review Comment:
assertEquals can not distinguish same expression in different address in
memory, it would treat them as different object
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]