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 23, 2024
1 parent 620244e commit e913f5e
Showing 1 changed file with 25 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(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));
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(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));
Expand All @@ -214,6 +231,14 @@ 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(1, 1, 1, 1, 1, 1)),
new IntegerLiteral(Integer.MAX_VALUE));
rewritten = executor.rewrite(secondsAdd, context);
Assertions.assertTrue(new DateTimeV2Literal("0069-01-19 03:14:07").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);
Expand Down

0 comments on commit e913f5e

Please sign in to comment.