Skip to content

Commit

Permalink
add more fe ut about overflow and underflow
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Sep 25, 2024
1 parent 620244e commit 7dd2bb1
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Interval.TimeUnit;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.trees.plans.RelationId;
Expand Down Expand Up @@ -196,6 +197,14 @@ void testFoldDate() {
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(9999, 12, 31, 23, 1, 1)),
new IntegerLiteral(24));
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));
Expand All @@ -205,6 +214,14 @@ void testFoldDate() {
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(9999, 12, 31, 23, 59, 1)),
new IntegerLiteral(1440));
rewritten = executor.rewrite(minutesAdd, context);
Assertions.assertTrue(new NullLiteral().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));
Expand All @@ -214,13 +231,24 @@ void testFoldDate() {
new IntegerLiteral(1));
rewritten = executor.rewrite(secondsAdd, context);
Assertions.assertTrue(new DateTimeV2Literal("0001-01-01 00:00:01").compareTo((Literal) rewritten) == 0);
secondsAdd = new SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 23, 59, 59)),
new IntegerLiteral(86400));
rewritten = executor.rewrite(secondsAdd, context);
Assertions.assertTrue(new NullLiteral().compareTo((Literal) rewritten) == 0);
secondsAdd = new SecondsAdd(DateV2Literal.fromJavaDateType(LocalDateTime.of(0, 1, 1, 0, 1, 1)),
new IntegerLiteral(-61));
rewritten = executor.rewrite(secondsAdd, context);
Assertions.assertTrue(new NullLiteral().compareTo((Literal) rewritten) == 0);

ToDays toDays = new ToDays(DateLiteral.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)));
rewritten = executor.rewrite(toDays, context);
Assertions.assertTrue(new IntegerLiteral(366).compareTo((Literal) rewritten) == 0);
toDays = new ToDays(DateV2Literal.fromJavaDateType(LocalDateTime.of(1, 1, 1, 1, 1, 1)));
rewritten = executor.rewrite(toDays, context);
Assertions.assertTrue(new IntegerLiteral(366).compareTo((Literal) rewritten) == 0);
toDays = new ToDays(DateV2Literal.fromJavaDateType(LocalDateTime.of(9999, 12, 31, 1, 1, 1)));
rewritten = executor.rewrite(toDays, context);
Assertions.assertTrue(new IntegerLiteral(3652424).compareTo((Literal) rewritten) == 0);
}

@Test
Expand Down

0 comments on commit 7dd2bb1

Please sign in to comment.