From 7dd2bb1344105ed85099d8e5ce76eaba42444cce Mon Sep 17 00:00:00 2001 From: LiBinfeng <1204975323@qq.com> Date: Mon, 23 Sep 2024 11:21:47 +0800 Subject: [PATCH] add more fe ut about overflow and underflow --- .../rules/expression/FoldConstantTest.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java index 3a8252fe9d75c6..c88fae0e24b118 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/expression/FoldConstantTest.java @@ -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; @@ -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)); @@ -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)); @@ -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(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); @@ -221,6 +246,9 @@ void testFoldDate() { 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