asolimando commented on code in PR #2876:
URL: https://github.com/apache/calcite/pull/2876#discussion_r1020908293
##########
core/src/main/java/org/apache/calcite/rex/RexInterpreter.java:
##########
@@ -342,22 +346,15 @@ private static Comparable ceil(RexCall call,
List<Comparable> values) {
default:
break;
}
- final TimeUnitRange subUnit = subUnit(unit);
- for (long v2 = v;;) {
- final int e = DateTimeUtils.unixTimestampExtract(subUnit, v2);
- if (e == 0) {
- return v2;
- }
- v2 -= unit.startUnit.multiplier.longValue();
- }
+ return ceilSubDay(call.getKind(), v, unit);
}
- private static TimeUnitRange subUnit(TimeUnitRange unit) {
- switch (unit) {
- case QUARTER:
- return TimeUnitRange.MONTH;
+ private static long ceilSubDay(SqlKind kind, Long v, TimeUnitRange unit) {
+ switch (kind) {
+ case FLOOR:
+ return SqlFunctions.floor(v, unit.startUnit.multiplier.longValue());
default:
- return TimeUnitRange.DAY;
+ return SqlFunctions.ceil(v, unit.startUnit.multiplier.longValue());
Review Comment:
If the `default` case is just for `ceil`, I'd rather cover it explicitly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]