fix round() handling of scale, precision, and nulls#2187
Merged
Conversation
max-hoffman
approved these changes
Dec 6, 2023
Contributor
max-hoffman
left a comment
There was a problem hiding this comment.
this looks OK, the variable naming in Round.Eval() kind of makes it kind of hard to tell what's going on though
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.
This PR has
ROUND()behavior match MySQL more closely specifically when handling NULLs.Additionally, it refactors the function to no longer use custom logic, and rely on
decimal.Decimallibrary for conversions.The slowness from the original issues stems from the
math.Pow()function that is attempting to raise precision to some huge negative number. This PR solves that problem by constraining the precision values to ourDecimalMaxScale(30).A better constraint would be
-308since that's the max scale of a float supported by MySQL. However, we don't go nearly as far. If we knew the scale of the passed in value we could also constrain the precision that way.This PR also rewrites the
ROUND()unit tests to be structured like other unit tests for functions, and fixes their handling of null arguments.fixes: dolthub/dolt#7073