From e913f5ee3f9fc46c1f0c68cf4ebe7a9d21bb4fe8 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 | 25 +++++++++++++++++++ 1 file changed, 25 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 3a8252fe9d75c66..29d309dd546acc3 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(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)); @@ -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)); @@ -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);