Repository navigation
Use decimal256 for decimal filter literals above 38 digits - #4526
Closed
rahulsmahadev wants to merge 1 commit into
Closed
rahulsmahadev wants to merge 1 commit into
rahulsmahadev wants to merge 1 commit into
Conversation
A literal past a precision-38 column's range, such as ratio < 1 on decimal(38, 38), has 39 digits at the column's scale, so the scan raised "precision should be between 1 and 38" building its decimal128 type. Use decimal256 above 38 digits; Arrow compares it with the column by value. Co-authored-by: Isaac <[email protected]>
Contributor
Author
|
@kevinjqliu, this is a follow-up to #4348: a filter literal past a decimal(38, s) column's range, such as |
Fokko
reviewed
Nov 30, 2026
Comment on lines
+931
to
+932
| if precision > 38: | ||
| return pa.decimal256(precision, iceberg_type.scale) |
Contributor
There was a problem hiding this comment.
Isn't this in conflict with the spec: https://iceberg.apache.org/spec/#primitive-types
It explicitly states:
Scale is fixed, precision must be 38 or less
Contributor
Author
|
Closing this one. Fair point on the spec: rather than decimal256, out-of-range decimal literals should fold at bind time with the sentinels from #4371. |
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
Bug: follow-up to #4348, also noted in the review of #4372. A literal past the range of a precision-38 decimal column has 39 or more digits at the column's scale, for example 1 on
decimal(38, 38). The filter is valid, but the scan builds the Arrow literal asdecimal128, which stops at 38 digits:Other comparisons and
NOT INfail too when they reach the Arrow filter, including whendelete()rewrites a file.Fix: in
_literal_arrow_type, usedecimal256for literals that need 39 to 76 digits at the column's scale. PyArrow compares adecimal128column with adecimal256scalar or value set by value, also on PyArrow 18. Literals that fit in 38 digits keep their type, and literals that need more than 76 digits still raise.Java's filters (the
ExpressionsAPI, Spark pushdown throughSparkV2Filters) bind inUnboundPredicate, where integer literals onlysetScale, and the manifest, metrics and row evaluators (Evaluator, whichGenericReaderapplies to residuals) compare theBigDecimalby value. This PR changes only the Arrow row filter; the existing NULL and scale-binding differences from Java remain.The alternative is to fold out-of-range decimal literals to always-true/false at bind, as open #4371 does for floats; its always-true result also includes NULL rows. This PR keeps the comparison by value of #4348.
Are these changes tested?
Yes,
test_decimal_literal_wider_than_decimal128_to_pyarrow(<,!=,IN,NOT INwith 10**20 ondecimal(38, 18)) andtest_row_filter_decimal_literal_wider_than_decimal128(ratio < 1,amount < 10**20andamount IN (10**20, -3)through a table scan) intests/io/test_pyarrow.py. Every case fails on main with theValueErrorabove and passes with this change.Are there any user-facing changes?
Yes, filters with decimal literals that need 39 to 76 digits at the column's scale return rows instead of raising.
Please add the
changeloglabel.This pull request and its description were written by Isaac.