Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interval values can overflow #24087

Open
tdcmeehan opened this issue Nov 19, 2024 · 2 comments
Open

Interval values can overflow #24087

tdcmeehan opened this issue Nov 19, 2024 · 2 comments

Comments

@tdcmeehan
Copy link
Contributor

tdcmeehan commented Nov 19, 2024

This produces the correct value:

presto> select interval '1' month * 2147483647;
    _col0    
-------------
 178956970-7 
(1 row)

The next higher number will overflow:

presto> select interval '1' month * 2147483648;
    _col0     
--------------
 -178956970-8 
(1 row)

None of the interval year to month operators for division, multiplication, subtraction and addition check boundaries, so this problem is not specific to multiplication. Also, similar boundary checks should be added for multiplication by double.

Likewise, the interval day time operators will also overflow and need the same checks, adjusted to work for the long type that backs IntervalDayTimeType.

Your Environment

This is true for any functional environment of Presto.

Expected Behavior

It should be an error to exceed the boundary of the interval type. The underlying datastructure for interval year to month is an integer, so we should raise an error for any value that exceed's Java integer range.

Current Behavior

The interval will silently overflow and return incorrect results.

Possible Solution

Modify the interval operators to do proper overflow checking, as is done for e.g. INTEGER operators.

Steps to Reproduce

See the above queries for a simple reproduction.

Screenshots (if appropriate)

Context

This was discovered while converting constant folding of expressions to use Velox for their evaluation.

This was previously reported in #9342.

@tdcmeehan tdcmeehan added the bug label Nov 19, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Unprioritized in Bugs and support requests Nov 19, 2024
@tdcmeehan tdcmeehan changed the title Interval values can overflow Interval Year Month values can overflow Nov 19, 2024
@tdcmeehan tdcmeehan changed the title Interval Year Month values can overflow Interval values can overflow Nov 19, 2024
@asharan2buff
Copy link

Can I take this up?

@tdcmeehan
Copy link
Contributor Author

@asharan2buff sure. I have opened #24089 to address the issue for IntervalYearMonthOperators, please take up IntervalDayTimeOperators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 Unprioritized
Development

No branches or pull requests

2 participants