Repository navigation
Convert float literals to wide decimal columns without InvalidOperation - #4372
Open
rahulsmahadev wants to merge 1 commit into
Open
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
FloatLiteral.to(DecimalType) and DoubleLiteral.to(DecimalType) quantize the value under the default 28-digit decimal context, so a value whose quantized form has more digits raised decimal.InvalidOperation: amt > 1e26 on a decimal(38, 2) column, or amt < 0.5 on a decimal(38, 30) column. Quantize under a context with enough precision for the result. Co-authored-by: Isaac <no-reply@databricks.com>
Contributor
Author
|
@kevinjqliu @AP24110011695 could you take a look when you have a chance? It is the finite-value counterpart of #4287: float filters on wide decimal columns no longer raise |
This branch has not been deployed
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.
Rationale for this change
A float filter on a wide decimal column raises
decimal.InvalidOperation:FloatLiteral.to(DecimalType)andDoubleLiteral.to(DecimalType)quantize the value to the column's scale under the default decimal context, which keeps 28 digits. When the quantized value has more digits than that (1e26with 2 decimals, or0.5with 30 decimals),quantizeraises. A decimal column can hold up to 38 digits, so these are valid filters.This change quantizes under a local context with enough precision for the result, in one helper used by both conversions. Rounding is unchanged (
ROUND_HALF_UP), and positive and negative infinity still raise theValueErroradded in #4287 for #4286. NaN remains rejected when a literal is constructed.Are these changes tested?
Yes.
test_float_to_decimal_conversion_beyond_default_context_precisionintests/expressions/test_literals.pyconverts2.0**87todecimal(38, 2)and0.5todecimal(38, 30)from both aFloatLiteraland aDoubleLiteral. It fails on main withdecimal.InvalidOperationand passes with this change.Are there any user-facing changes?
Bug fix: float filters on wide decimal columns no longer raise
decimal.InvalidOperation. No API changes.This pull request and its description were written by Isaac.