-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fix long overflow for scalar function sequence #16867
Conversation
@kasiafi Could you guide me about how to add test cases for this, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall.
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
@@ -52,8 +51,7 @@ public static Block sequence( | |||
|
|||
checkValidStep(start, stop, step); | |||
|
|||
int length = toIntExact((stop - start) / step + 1L); | |||
checkMaxEntry(length); | |||
int length = checkMaxEntry((stop - start) / step + 1L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that you identified a couple of other overflow candidates. Would you mind filing an issue about potential overflows in SequenceIntervalDayToSecond
and SequenceIntervalYearToMonth
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, filed #16894
Should I link the issue as well, or remove the change in this pr and separate it.
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Show resolved
Hide resolved
@kasiafi There are lots of possible cases that could overflow about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to simplify the code basing on your previous approach. I extracted three different cases so that for each case it should be easy to prove that there can be no overflow.
We should have a test covering a big step with small start and stop values, e.g. (-5, 5, 1000), (-5, 5, 7).
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to simplify the code basing on your previous approach. I extracted three different cases so that for each case it should be easy to prove that there can be no overflow.
We should have a test covering a big step with small start and stop values, e.g. (-5, 5, 1000), (-5, 5, 7).
core/trino-main/src/main/java/io/trino/operator/scalar/SequenceFunction.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
Description
Fix #16742
Additional context and related issues
Release notes
(x) Release notes are required, with the following suggested text: