Repository navigation
GH-46183: [C++][Compute] Make is_in and index_in treat -0.0 and +0.0 as equal - #54915
Closed
sankalpsthakur wants to merge 1 commit into
Closed
sankalpsthakur wants to merge 1 commit into
sankalpsthakur wants to merge 1 commit into
Conversation
… +0.0 as equal is_in and index_in look floating-point values up through their unsigned integer bit patterns, so -0.0 and +0.0 were different keys although they compare equal. A Parquet column that only holds zeros has statistics min=-0.0 and max=+0.0, which the dataset layer turns into the guarantee `x == -0.0`. That folded `x IN (0.0)` to false and silently dropped every row of the fragment. Fold -0.0 into +0.0, for both the value set and the probed values, when the value set is floating point.
|
|
|
|
richardliaw
pushed a commit
to ray-project/ray
that referenced
this pull request
Nov 20, 2026
…and integer overflow (#68325) ## Why A filter pushed into a Parquet read can return fewer rows than the same filter on materialized data: ```python pq.write_table(pa.table({"id": [0, 1], "x": [40.0, float("nan")]}), path) ds = ray.data.read_parquet(path) ds.filter(expr=col("x") != 40.0).take_all() # before: [] after: [{'id': 1, 'x': nan}] ds.materialize().filter(expr=col("x") != 40.0).take_all() # [{'id': 1, 'x': nan}] ``` `NaN != 40.0` is 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_in` with NaN in its list, and negated comparisons such as `~(x >= 30.0)` or `(x >= 30.0) == False`. Signed zero hits `is_in` too: `is_in([0.0])` on `[-0.0, 0.0]` skips the group. `<`, `<=`, `>`, `>=`, `==` and `is_in` with 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 + 100` with `x = 100` wraps to `-56`, while Ray's in-memory filter widens to int64 and gets `200`. `filter(expr=(col("x") + 100) > 120)` returns no rows instead of one. ## Changes `datasource_v2/common/pushdown_utils.py` adds two checks: `is_statistics_safe` (a float column is used only in `<`, `<=`, `>`, `>=`, `==`, a null check, or `is_in` with no NaN or zero in its list) and `has_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. - V2, `formats/parquet/parquet_scanner.py`: `push_filters` checks each part of a top-level `&` on its own, so `(x != 40.0) & (id >= 0)` still pushes `id >= 0`. - V1, `datasource/parquet_datasource.py`: V1 pushes a filter whole or not at all, so `apply_predicate` keeps the whole filter after the read if any part fails. - `tests/test_predicate_pushdown.py`: `test_pushed_filter_matches_in_memory_filter` compares 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: | Filter | Row groups read, before | After | | --- | --- | --- | | `x != 40.0`, `x.not_in([40.0])` | 100 | 100 | | `~(x >= 30.0)` | 31 | 100 | | `x.is_in([40.0, 41.0])` | 2 | 2 | | `x < 30.0` | 31 | 31 | A 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 - Not a duplicate: no open issue or PR covers this. #67855 adds a separate pruning path that copies both checks; it will import them from here once this lands. - `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 (the `x > 30.0` case, which is safe). - AI assistance was used; I reviewed every changed line. Signed-off-by: Aarrya <[email protected]> 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Aarrya <[email protected]> Co-authored-by: Claude Fable 5.2 <[email protected]>
Member
|
Closing this PR as it doesn't meet our guidelines on AI-generated contributions: If you'd like to contribute this change, please review and test the code yourself, then open a new PR. |
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
is_inandindex_inlook floating-point values up through their unsigned integer bit patterns, so-0.0and+0.0are different keys even thoughequaltreats them as the same value:This silently drops rows from dataset scans. The Parquet format asks writers to put
-0.0in the min and+0.0in the max statistic when the computed value is zero, so a column that only holds zeros gets min=-0.0, max=+0.0.EvaluateStatisticsAsExpressionturns that into the guaranteex == -0.0,SimplifyWithGuaranteesubstitutesxby-0.0and constant-foldsx IN (0.0)through theis_inkernel, which says false, so the whole fragment is skipped:The reporter's analysis in the issue traced the empty result to the signed zero in the Parquet statistics.
What changes are included in this PR?
SetLookupStateinscalar_set_lookup.ccfolds the bit pattern of-0.0into+0.0, both when the value set is built and when values are probed, if the value set is floating-point. Integers of the same width are not touched (their smallest value has the same bit pattern as-0.0).I did not change
ScalarHelper<float/double>::ComputeHashinhashing.h, which is where the issue discussion pointed. These kernels do not use it:InitStateVisitormaps every fixed-width numeric type to an unsigned integer state, so it isScalarMemoTable<uint64_t>that hashes doubles here. AndScalarMemoTableis also the table behindunique,value_counts,dictionary_encode,DictionaryBuilderand the Parquet dictionary encoder, where merging-0.0into0.0would silently change stored values (a dictionary-encoded Parquet column keeps the sign of zero across a round trip today; see also ARROW-10211). So this only makes set membership agree withequal. NaN handling, the other hash-based kernels and the Acero hash join / group_by (which still keep the two zeros apart) are unchanged.Are these changes tested?
Yes: C++ tests for
is_inandindex_inon float and double (single, chunked and duplicated value sets, and integer guards) inscalar_set_lookup_test.cc,Expression.SimplifyIsInSignedZerofor the dataset guarantee path, and two pytests (test_is_in_index_in_signed_zero,test_filter_isin_signed_zero). They fail without the change.Are there any user-facing changes?
is_inandindex_inon float and double now match-0.0with+0.0and the reverse, asequaldoes.This PR contains a "Critical Fix". It fixes (b), a bug that caused incorrect data to be produced: dataset filters using
isinon a float column silently returned no rows for fragments whose values are all zero.Was AI used for this PR?
PR code and description written by:
Reviewed before submission by:
AI disclosure: an AI coding tool wrote the fix, the tests and this description; the tests were run with and without the change before submitting.