Repository navigation
[Data] Stop Parquet filter pushdown from dropping rows on NaN floats and integer overflow - #68325
Conversation
…olumns Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]> Signed-off-by: Aarrya <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request addresses an issue where Parquet row-group pruning can incorrectly drop NaN rows because Parquet min/max statistics skip NaN values. It introduces a safety check, is_statistics_safe, to identify predicates that are safe to push down on float columns, and updates both ParquetDatasource and ParquetScanner to only push down safe filters while keeping unsafe ones above the read. The review feedback suggests optimizing this safety check by precomputing and passing the set of float columns through recursive calls and during filter pushdown planning to avoid redundant schema scans.
| return is_statistics_safe( | ||
| predicate=predicate.left, schema=schema | ||
| ) and is_statistics_safe(predicate=predicate.right, schema=schema) | ||
| float_columns = {field.name for field in schema if pa.types.is_floating(field.type)} |
There was a problem hiding this comment.
Similar to Gemini’s comment, this line rebuilds the float-column set for each visited leaf. Precomputing it in push_filters covers V2, but V1 still passes only schema. If the helper builds the set after recursing into AND/OR, V1 still repeats the scan. Could we compute it once per planning call and pass only the set to the internal checker?
I compared 3021ed6 with the once-per-call variant on single-node Ray with PyArrow 23.0.1:
| Check | PR head | Once per call |
|---|---|---|
| Focused Ray tests (14 from this PR + 22 additional V1/V2 cases) | 36 passed | 36 passed |
| Schema field type checks (256 columns, 32 terms; both paths) | 8,192 | 256 |
| V1 safety check (2,048-column synthetic schema) | 34.0 ms | 1.20 ms |
| V2 predicate planning (2,048-column synthetic schema) | 36.5 ms | 1.15 ms |
The 22 additional cases matched on expected row IDs and pushdown/residual decisions. The timings are for planning only, not Parquet read latency. I’d treat this as non-blocking.
There was a problem hiding this comment.
Thanks for measuring this. Done in 6304dd7: float_column_names(schema) builds the set once per planning call and is_statistics_safe takes the set, for both V1 and V2.
Keep unsafe float predicates and column arithmetic out of the residual hint so mixed partition/data filters retain matching rows. Add both row-loss regressions and address the named-argument and docstring review comments. Reuse is_statistics_safe unchanged from Aarrya Saraf's PR ray-project#68325: ray-project#68325 Source revision: 3021ed6. Only the shared helper is included; the existing-filter pushdown fixes remain in ray-project#68325. Validated the residual, footer, planning, and synthesized-column tests on PyArrow 23.0.1, 25.0.1, and 26.0.1. Local checks also covered ordinary UDF fallback and the arithmetic pruning boundary. Pre-commit passed. Co-authored-by: Aarrya <[email protected]> Signed-off-by: mora <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
|
Pushed Lists with zero stay after the read because PyArrow's statistics don't tell -0.0 from 0.0: pq.write_table(pa.table({"x": [-0.0, 0.0]}), path)
ray.data.read_parquet(path).filter(expr=col("x").is_in([0.0])).take_all()
# pushed: [] in memory: [{'x': 0.0}]The other filters stay after the read. For |
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Aarrya <[email protected]>
| """ | ||
| # Filters PyArrow would evaluate differently from Ray must stay in the | ||
| # ``Filter`` above the read; returning ``self`` keeps it there. | ||
| if has_column_arithmetic(expr=predicate_expr) or not is_statistics_safe( |
There was a problem hiding this comment.
In V1, if any part of the filter is risky, this returns early and pushes nothing. That includes partition pruning (skipping folders like country=CA/), which is always safe. Example: a table with country=US/CA/DE/FR and filter((col("country") == "US") & (col("x") != 1.0)) read 1 file before this PR and reads all 4 with it. On a table split by date, that means reading every date instead of one. This hits users who switch to V1 with use_datasource_v2=False.
The pushdown rule already splits A & B into parts it pushes and parts it keeps as a Filter (PredicatePushdown._split_by_convertibility). Could risky parts go into the "keep" list there? Then V1 still skips partitions and pushes the safe parts, as the V2 change in this PR does.
There was a problem hiding this comment.
You're right this is a v1 regression but this is parquet specific and v1 for parquet is deprecated
| return {field.name for field in schema if pa.types.is_floating(field.type)} | ||
|
|
||
|
|
||
| def is_statistics_safe(predicate: Expr, float_columns: AbstractSet[str]) -> bool: |
There was a problem hiding this comment.
Iceberg metadata contains NaN counts so this wont be an issue there.
| "int8_add", | ||
| ], | ||
| ) | ||
| def test_pushed_filter_matches_in_memory_filter( |
There was a problem hiding this comment.
This test only compares rows, so it also passes if nothing is pushed at all. For example, it doesn't notice that in V1, filter((col("country") == "US") & (col("x") != 1.0)) on a partitioned table now reads every partition instead of one. Could it also check what gets pushed? For example: on V2, ne_and_int still pushes id >= 0; and on V1, a table with a partition column still skips the other partitions.
abhishekverma-ray
left a comment
There was a problem hiding this comment.
Overall LGTM, this fixes silently dropped rows on the default path. Left some non-blocking comments inline.
Could you open a follow-up for the V1 partition-pruning slowdown, and use the same checks for Iceberg (#68152 or an issue)?
Use partition facts and the existing Arrow footer pruning path during Datasource V2 listing, retaining the full residual filter after the read. Keep safe AND conjuncts eligible for pruning when other conjuncts are unsafe. Rebase onto d6432c7 after ray-project#68325 merged and import its shared float and arithmetic checks instead of carrying local copies. Consolidate the reader-cast regression with the NaN and integer-overflow cases. Signed-off-by: mora <[email protected]>
A filtered count whose predicate the scanner only partially pushes (ray-project#68325 declines NaN-unsafe float comparisons and column arithmetic) keeps a residual Filter above the read. That Filter requires its columns, so the read's projection cannot be empty and the exact-count stub cannot fire while the residual still has rows to drop. Pin the plan shape so the two conditions stay mutually exclusive. Signed-off-by: Dev Sharma <[email protected]>
Use partition facts and the existing Arrow footer pruning path during Datasource V2 listing, retaining the full residual filter after the read. Keep safe AND conjuncts eligible for pruning when other conjuncts are unsafe. Rebase onto d6432c7 after ray-project#68325 merged and import its shared float and arithmetic checks instead of carrying local copies. Consolidate the reader-cast regression with the NaN and integer-overflow cases. Signed-off-by: mora <[email protected]>
Use partition facts and the existing Arrow footer pruning path during Datasource V2 listing, retaining the full residual filter after the read. Keep safe AND conjuncts eligible for pruning when other conjuncts are unsafe. Rebase onto d6432c7 after ray-project#68325 merged and import its shared float and arithmetic checks instead of carrying local copies. Consolidate the reader-cast regression with the NaN and integer-overflow cases. Signed-off-by: mora <[email protected]>
Why
A filter pushed into a Parquet read can return fewer rows than the same filter on materialized data:
NaN != 40.0is true in Arrow, NumPy and Spark, so row 1 matches. It is lost because PyArrow skips whole row groups using the min/max in the Parquet footer, and those min/max leave NaN out. The group[40.0, NaN]is stored as min = max = 40.0, which reads as "every value is 40", so PyArrow skips it. Whether the row comes back depends on its neighbours: a group[35.0, NaN]keeps it.Only filters that can match NaN are hit:
!=,not_in,is_inwith NaN in its list, and negated comparisons such as~(x >= 30.0)or(x >= 30.0) == False. Signed zero hitsis_intoo:is_in([0.0])on[-0.0, 0.0]skips the group.<,<=,>,>=,==andis_inwith neither NaN nor zero in its list never lose a row, so skipping on them is safe.A second bug has the same symptom. PyArrow computes arithmetic in a pushed filter in the column's own type, so on an int8 column
x + 100withx = 100wraps to-56, while Ray's in-memory filter widens to int64 and gets200.filter(expr=(col("x") + 100) > 120)returns no rows instead of one.Changes
datasource_v2/common/pushdown_utils.pyadds two checks:is_statistics_safe(a float column is used only in<,<=,>,>=,==, a null check, oris_inwith no NaN or zero in its list) andhas_column_arithmetic. A filter that fails either one is not pushed into the scan; Ray runs it on the rows after reading, as it does for any filter it cannot push.formats/parquet/parquet_scanner.py:push_filterschecks each part of a top-level&on its own, so(x != 40.0) & (id >= 0)still pushesid >= 0.datasource/parquet_datasource.py: V1 pushes a filter whole or not at all, soapply_predicatekeeps the whole filter after the read if any part fails.tests/test_predicate_pushdown.py:test_pushed_filter_matches_in_memory_filtercompares pushed and in-memory results for 9 filters on V1 and V2.Cost
Filters that are no longer pushed lose row-group skipping. On a sorted float column with 100 row groups:
x != 40.0,x.not_in([40.0])~(x >= 30.0)x.is_in([40.0, 41.0])x < 30.0A TODO on each check names the upstream fix: NaN and signed zero in PyArrow's statistics (apache/arrow#50807, apache/arrow#54915), and widening in
Expr.to_pyarrow().Checks
pytest python/ray/data/tests/test_predicate_pushdown.py -k test_pushed_filter_matches_in_memory_filter -v: 18 passed. With both checks disabled: 16 failed, 2 passed (thex > 30.0case, which is safe).Signed-off-by: Aarrya [email protected]
🤖 Generated with Claude Code