[fix](Nereids) DatetimeV2 round floor and round ceiling is wrong (#35153) (#35155)

pick from master #35153

1.  round floor was incorrectly implemented as round
2. round ceiling not really round because use double type when divide
This commit is contained in:
morrySnow
2024-05-22 16:23:20 +08:00
committed by GitHub
parent 30a66a4f9d
commit 9ed4a2023b
4 changed files with 39 additions and 7 deletions

View File

@ -232,7 +232,7 @@ public class DateTimeV2Literal extends DateTimeLiteral {
long newYear = year;
if (remain != 0) {
newMicroSecond = Double
.valueOf((microSecond + (Math.pow(10, 6 - newScale)))
.valueOf((microSecond + (int) (Math.pow(10, 6 - newScale)))
/ (int) (Math.pow(10, 6 - newScale)) * (Math.pow(10, 6 - newScale)))
.longValue();
}
@ -251,8 +251,8 @@ public class DateTimeV2Literal extends DateTimeLiteral {
}
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) {