Skip to content

Commit

Permalink
[fix](Nereids) DatetimeV2 round floor was incorrectly implemented as …
Browse files Browse the repository at this point in the history
…round ceil
  • Loading branch information
morrySnow committed May 21, 2024
1 parent 1120f96 commit 6794192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ public DateTimeV2Literal roundCeiling(int newScale) {
}

public DateTimeV2Literal roundFloor(int newScale) {
// use roundMicroSecond in constructor
return new DateTimeV2Literal(DateTimeV2Type.of(newScale), year, month, day, hour, minute, second, microSecond);
return new DateTimeV2Literal(DateTimeV2Type.of(newScale), year, month, day, hour, minute, second,
microSecond / (int) Math.pow(10, 6 - newScale) * (int) Math.pow(10, 6 - newScale));
}

public static Expression fromJavaDateType(LocalDateTime dateTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,17 @@ void testDateTimeV2Scale() {
new DateTimeV2Literal(DateTimeV2Type.of(5), "2016-12-31 23:59:59.999999"),
new DateTimeV2Literal("2017-01-01 00:00:00.0"));
}

@Test
void testRoundFloor() {
DateTimeV2Literal literal;
literal = new DateTimeV2Literal(DateTimeV2Type.of(6), 2000, 2, 2, 2, 2, 2, 222222);
Assertions.assertEquals(222222, literal.roundFloor(6).microSecond);
Assertions.assertEquals(222220, literal.roundFloor(5).microSecond);
Assertions.assertEquals(222200, literal.roundFloor(4).microSecond);
Assertions.assertEquals(222000, literal.roundFloor(3).microSecond);
Assertions.assertEquals(220000, literal.roundFloor(2).microSecond);
Assertions.assertEquals(200000, literal.roundFloor(1).microSecond);
Assertions.assertEquals(0, literal.roundFloor(0).microSecond);
}
}

0 comments on commit 6794192

Please sign in to comment.