Skip to content

[python] Fix DECIMAL Arrow predicates across scales - #10317

Open
wangzhigang1999 wants to merge 3 commits into
apache:masterfrom
wangzhigang1999:fix/decimal-arrow-predicate-20260929
Open

wangzhigang1999 wants to merge 3 commits into
apache:masterfrom
wangzhigang1999:fix/decimal-arrow-predicate-20260929

Conversation

@wangzhigang1999

@wangzhigang1999 wangzhigang1999 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

On PyArrow 19.0.1, filtering a DECIMAL(15, 2) column with < Decimal('2') can return no rows where 1.00 and 1.01 should 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, and BETWEEN predicates. The bound is never rounded into an equality match.

Fixes #10316. The underlying Arrow behavior is tracked in apache/arrow#41011.

Tests

  • Targeted predicate and read tests on PyArrow 19.0.1 and 22.0.0: 213 passed and 32 subtests passed per version.
  • Ruff format/check and Black -S --check passed for the new files and changed code; Pyright reported no errors in the new module.
  • A three-round local SF10 read benchmark on PyArrow 22.0.0 passed 48/48 correctness checks. Measured DECIMAL read times showed no material regression.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PyPaimon DECIMAL range filters return wrong rows with PyArrow 19

2 participants