Skip to content

Commit

Permalink
add fe ut
Browse files Browse the repository at this point in the history
  • Loading branch information
LiBinfeng-01 committed Sep 19, 2024
1 parent e291317 commit adc4856
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@
import org.apache.doris.nereids.trees.expressions.functions.scalar.DateFormat;
import org.apache.doris.nereids.trees.expressions.functions.scalar.DateTrunc;
import org.apache.doris.nereids.trees.expressions.functions.scalar.FromUnixtime;
import org.apache.doris.nereids.trees.expressions.functions.scalar.HoursAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.MinutesAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.SecondsAdd;
import org.apache.doris.nereids.trees.expressions.functions.scalar.StrToDate;
import org.apache.doris.nereids.trees.expressions.functions.scalar.ToDays;
import org.apache.doris.nereids.trees.expressions.functions.scalar.UnixTimestamp;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
Expand Down Expand Up @@ -179,6 +183,46 @@ 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);

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);

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);

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);
}

@Test
void testFoldString() {
executor = new ExpressionRuleExecutor(ImmutableList.of(
Expand Down

0 comments on commit adc4856

Please sign in to comment.