[python] Fix DECIMAL Arrow predicates across scales - #10317
Open
wangzhigang1999 wants to merge 3 commits into
Open
wangzhigang1999 wants to merge 3 commits into
wangzhigang1999 wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The implementation correctly preserves DECIMAL bound semantics and includes strong regression coverage.
Review effort: Balanced
Findings: None
What changed in this PR
Fixes incorrect DECIMAL filtering when Arrow literals and columns use different scales.
Changes:
- Generates exact, scale-aware Arrow DECIMAL expressions.
- Supplies schemas during pushdown and post-read filtering.
- Adds comprehensive comparison, range, set, evolution, and integration tests.
| File | Description |
|---|---|
common/decimal_arrow_predicate.py |
Implements exact DECIMAL expression generation. |
common/predicate.py |
Adds schema-aware DECIMAL conversion. |
read/split_read.py |
Supplies physical schemas for pushdown. |
read/reader/filter_record_batch_reader.py |
Uses batch schemas for residual filtering. |
tests/decimal_predicate_test.py |
Covers DECIMAL predicate behavior comprehensively. |
tests/where_parser_test.py |
Adds SQL range regression coverage. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Purpose
On PyArrow 19.0.1, filtering a
DECIMAL(15, 2)column with< Decimal('2')can return no rows where1.00and1.01should match. Arrow evaluates the literal at a different scale from the column.Pass the physical Arrow schema into predicate conversion and build exact DECIMAL comparisons at the column's scale. This covers file pushdown and post-read batch filtering, including range,
IN, andBETWEENpredicates. The bound is never rounded into an equality match.Fixes #10316. The underlying Arrow behavior is tracked in apache/arrow#41011.
Tests
-S --checkpassed for the new files and changed code; Pyright reported no errors in the new module.