XuQianJin-Stars commented on a change in pull request #1618: [hotfix] Fixed an
issue where overflow from Long to Int was unsafe
URL: https://github.com/apache/calcite/pull/1618#discussion_r352324039
##########
File path: core/src/main/java/org/apache/calcite/rex/RexInterpreter.java
##########
@@ -213,7 +213,7 @@ private Comparable extract(RexCall call, List<Comparable>
values) {
final int v2;
if (v instanceof Long) {
// TIMESTAMP
- v2 = (int) (((Long) v) / TimeUnit.DAY.multiplier.longValue());
+ v2 = Math.toIntExact(((Long) v) / TimeUnit.DAY.multiplier.longValue());
Review comment:
> One think I don't understand here is `v2` is still used as `long` in the
following code `DateTimeUtils.unixDateExtract(timeUnitRange, v2);`. Maybe the
right fix is do not do long -> int conversion?
`v2 = (Integer) v; ` should we cast to `long` too? If it was you would have
to handle the `int` and `long` cases separately for
`DateTimeUtils.unixDateExtract (timeUnitRange, v2)`;
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services