rahulsmahadev opened a new pull request, #4526:
URL: https://github.com/apache/iceberg-python/pull/4526
# 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 as `decimal128`, which stops at 38 digits:
```python
# ratio is decimal(38, 38), amount is decimal(38, 18)
tbl.scan(row_filter=LessThan("ratio", 1)).to_arrow()
# ValueError: precision should be between 1 and 38
tbl.scan(row_filter=In("amount", {10**20, -3})).to_arrow()
# ValueError: precision should be between 1 and 38
```
Other comparisons and `NOT IN` fail too when they reach the Arrow filter,
including when `delete()` rewrites a file.
Fix: in `_literal_arrow_type`, use `decimal256` for literals that need 39 to
76 digits at the column's scale. PyArrow compares a `decimal128` column with a
`decimal256` scalar 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 `Expressions` API, Spark pushdown through
`SparkV2Filters`) bind in `UnboundPredicate`, where integer literals only
`setScale`, and the manifest, metrics and row evaluators (`Evaluator`, which
`GenericReader` applies to residuals) compare the `BigDecimal` by 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 IN` with 10**20 on `decimal(38, 18)`) and
`test_row_filter_decimal_literal_wider_than_decimal128` (`ratio < 1`, `amount <
10**20` and `amount IN (10**20, -3)` through a table scan) in
`tests/io/test_pyarrow.py`. Every case fails on main with the `ValueError`
above 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 `changelog` label.
This pull request and its description were written by Isaac.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]