Repository navigation
DX-90291: Gandiva: fix round(double, scale) overflow for large values - #148
Merged
victor6567758 merged 2 commits intoOct 17, 2026
Merged
victor6567758 merged 2 commits into
victor6567758 merged 2 commits into
Conversation
victor6567758
force-pushed
the
DX-90291-gandiva-round
branch
from
October 16, 2026 15:04
12df724 to
a097c4f
Compare
alinaliBQ
reviewed
Oct 16, 2026
victor6567758
force-pushed
the
DX-90291-gandiva-round
branch
from
October 16, 2026 17:36
a097c4f to
4cbf105
Compare
victor6567758
marked this pull request as ready for review
October 16, 2026 17:40
lriggs
reviewed
Oct 16, 2026
lriggs
previously approved these changes
Oct 16, 2026
lriggs
left a comment
Collaborator
There was a problem hiding this comment.
Learned something new:
Ulp: unit in the last place or unit of least precision (ulp) is the spacing between two consecutive floating-point numbers, i.e., the value the least significant digit (rightmost digit) represents if it is 1. It is used as a measure of accuracy in numeric calculations.
victor6567758
force-pushed
the
DX-90291-gandiva-round
branch
from
October 16, 2026 19:46
94cbf79 to
9e92a1b
Compare
Author
|
@alinaliBQ @lriggs please review after suggested fixes. |
alinaliBQ
reviewed
Oct 16, 2026
victor6567758
force-pushed
the
DX-90291-gandiva-round
branch
from
October 16, 2026 23:13
9e92a1b to
59b548e
Compare
lriggs
approved these changes
Oct 16, 2026
Collaborator
|
Also consider creating a GH issue in apache/arrow and making this fix upstream as well. |
victor6567758
merged commit Oct 17, 2026
f54c22e
into
dremio:dremio_27.0_23_19
20 of 40 checks passed
lriggs
pushed a commit
that referenced
this pull request
Oct 20, 2026
…#148) * DX-90291: Gandiva: fix round(double, scale) overflow for large values * DX-90291: Rename round limit constant, document float32 use
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
round(double_field, 100)returned Infinity for large values.Cause:
round_float64_int32andround_float32_int32(ROUND_DECIMAL_TO_SCALE) multiplied the number by10^scalebefore rounding. That overflowed toinf(or toNaNfor a huge scale). For a large scale it also lost the last digit, for exampleround(451.65, 100)returned451.65000000000003.Fix: return the number unchanged when
abs(number) >= 2^52 / 10^scale. The check runs before the multiplication, so nothing can overflow. At that magnitude the scaled value has no fractional part, so there is nothing to round. The negated comparison also returnsNaNand±infunchanged. A huge positive scale suchas
400, where10^scaleisinf, returns the input too.Note:
if (!(fabs(number) < kMaxRoundableScaledValue / scale_multiplier)): Negated<so thatNaN, for which every comparison isfalse, also takes the early return along with large values and±inf.Known limits (out of scope):
NaN.abs(number * 10^scal) ≈ 2^52, the multiply-round-divide approach can be one ulp off at ties. The old code did the same, so this is not a regression.TEST
Tests: new assertions in
TestExtendedMathOps.TestRoundDecimal(large values, their negatives, and a last-digit case at scale 100).SELECT double_field,round(double_field,3),round(double_field,4),round(double_field,7),round(double_field,10),round(double_field,100),round(double_field,8),round(double_field,-100) FROM gandiva_functions."numbers.parquet" where double_field != 0is attached to the story: https://dremio.atlassian.net/browse/DX-90291?issueKey=DX-90291