Repository navigation
[Data] Raise instead of keeping every file when a partition filter can't be evaluated - #65990
Merged
goutamvenkat-anyscale merged 2 commits intoSep 9, 2026
Conversation
…n't be evaluated Signed-off-by: Aarrya <[email protected]>
Narrowing `except Exception` to `except KeyError` only changes behaviour for predicates that raised. Everything that already returned a real answer must keep returning the same one, so assert that directly: correctly typed comparisons, compound AND/OR over partition columns, is_null, is_in, and a UDF over a partition column -- plus the missing-column case, which is the one thing the narrowed handler still swallows. All 13 cases pass unchanged against master's `except Exception`; only the type-mismatch test flips. That A/B is what makes the narrowing defensible. Signed-off-by: Aarrya <[email protected]>
AarryaSaraf
force-pushed
the
data-fix-partition-filter-fail-open
branch
from
September 8, 2026 23:23
74356b5 to
c91d3eb
Compare
AarryaSaraf
marked this pull request as ready for review
September 9, 2026 00:05
Contributor
There was a problem hiding this comment.
Code Review
This pull request narrows the exception handling in evaluate_predicate_on_partition from catching all exceptions (Exception) to only catching KeyError. This ensures that type mismatches (such as comparing a string partition value to an integer) correctly propagate errors instead of silently swallowing them and keeping every file. Comprehensive unit tests have been added to verify this new behavior and ensure that unaffected cases continue to work correctly. I have no feedback to provide as the changes are well-implemented and covered by tests.
goutamvenkat-anyscale
approved these changes
Sep 9, 2026
NightWing1998
pushed a commit
to NightWing1998/ray
that referenced
this pull request
Sep 11, 2026
…n't be evaluated (ray-project#65990) ## Why `PathPartitionParser.evaluate_predicate_on_partition` catches every exception and answers `True` -- "keep this file". A predicate Arrow can't evaluate is therefore answered `True` for every file, so the filter silently disappears and the query returns the whole table: ```python # hive-partitioned by year; partition values parse as strings ds.filter(expr=col("year") == 2020).count() # -> every row, no error ``` The identical mismatch on a data column already raises `ArrowNotImplementedError`. One user error, two opposite behaviours, decided only by whether the value is in the file or in the directory name. Narrowing the handler to `KeyError` keeps the one case that legitimately can't be decided -- a path carrying no value for a partition column the predicate names, as in a mixed-depth layout -- and lets the type mismatch propagate exactly as it does for data columns. ## Why `KeyError` and not something wider The swallowed errors are not one kind. Probing the failure modes against a string partition value: `==` and `>` against an int raise `ArrowNotImplementedError`, `is_in` raises `ArrowTypeError`, arithmetic raises `TypeError`, and an unknown column raises `KeyError`. Three of those four are the same user error -- a type mismatch -- wearing three exception types, so an allowlist of "errors to raise" would be leaky by construction. The benign case is exactly one type. Narrowing to it is the only cut that separates them cleanly. Adding `except Exception: return True` underneath would restore the old behaviour in full, so it is not a safety net; it is a revert. ## What doesn't change Narrowing only changes behaviour for predicates that previously *raised*. Everything that already returned a real answer must return the same one, so that is asserted directly in `test_evaluate_predicate_on_partition_unaffected_cases`: correctly typed `==` / `!=` / `>`, compound `&` and `|` over partition columns, `is_null`, `is_in`, and a UDF over a partition column -- plus the missing-column case, which is the one thing the narrowed handler still swallows. All 13 of those pass unchanged against master's `except Exception`. Only the type-mismatch test flips. That A/B is what makes the narrowing defensible. ## Test ``` pytest python/ray/data/tests/test_partitioning.py ``` On this branch: 32 failed, 51 passed. On unmodified master: 32 failed, 37 passed. The same 32 failures either way -- they are pre-existing S3 failures in my environment -- so the delta is exactly the 14 added tests, and nothing regressed. `test_evaluate_predicate_on_partition_type_mismatch` fails on master with `DID NOT RAISE ArrowNotImplementedError` and passes here. AI assistance was used to write this change. --------- Signed-off-by: Aarrya <[email protected]>
nadongjun
pushed a commit
to nadongjun/ray
that referenced
this pull request
Oct 6, 2026
…n't be evaluated (ray-project#65990) ## Why `PathPartitionParser.evaluate_predicate_on_partition` catches every exception and answers `True` -- "keep this file". A predicate Arrow can't evaluate is therefore answered `True` for every file, so the filter silently disappears and the query returns the whole table: ```python # hive-partitioned by year; partition values parse as strings ds.filter(expr=col("year") == 2020).count() # -> every row, no error ``` The identical mismatch on a data column already raises `ArrowNotImplementedError`. One user error, two opposite behaviours, decided only by whether the value is in the file or in the directory name. Narrowing the handler to `KeyError` keeps the one case that legitimately can't be decided -- a path carrying no value for a partition column the predicate names, as in a mixed-depth layout -- and lets the type mismatch propagate exactly as it does for data columns. ## Why `KeyError` and not something wider The swallowed errors are not one kind. Probing the failure modes against a string partition value: `==` and `>` against an int raise `ArrowNotImplementedError`, `is_in` raises `ArrowTypeError`, arithmetic raises `TypeError`, and an unknown column raises `KeyError`. Three of those four are the same user error -- a type mismatch -- wearing three exception types, so an allowlist of "errors to raise" would be leaky by construction. The benign case is exactly one type. Narrowing to it is the only cut that separates them cleanly. Adding `except Exception: return True` underneath would restore the old behaviour in full, so it is not a safety net; it is a revert. ## What doesn't change Narrowing only changes behaviour for predicates that previously *raised*. Everything that already returned a real answer must return the same one, so that is asserted directly in `test_evaluate_predicate_on_partition_unaffected_cases`: correctly typed `==` / `!=` / `>`, compound `&` and `|` over partition columns, `is_null`, `is_in`, and a UDF over a partition column -- plus the missing-column case, which is the one thing the narrowed handler still swallows. All 13 of those pass unchanged against master's `except Exception`. Only the type-mismatch test flips. That A/B is what makes the narrowing defensible. ## Test ``` pytest python/ray/data/tests/test_partitioning.py ``` On this branch: 32 failed, 51 passed. On unmodified master: 32 failed, 37 passed. The same 32 failures either way -- they are pre-existing S3 failures in my environment -- so the delta is exactly the 14 added tests, and nothing regressed. `test_evaluate_predicate_on_partition_type_mismatch` fails on master with `DID NOT RAISE ArrowNotImplementedError` and passes here. AI assistance was used to write this change. --------- Signed-off-by: Aarrya <[email protected]>
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.
Why
PathPartitionParser.evaluate_predicate_on_partitioncatches every exceptionand answers
True-- "keep this file". A predicate Arrow can't evaluate istherefore answered
Truefor every file, so the filter silently disappearsand the query returns the whole table:
The identical mismatch on a data column already raises
ArrowNotImplementedError. One user error, two opposite behaviours, decidedonly by whether the value is in the file or in the directory name.
Narrowing the handler to
KeyErrorkeeps the one case that legitimatelycan't be decided -- a path carrying no value for a partition column the
predicate names, as in a mixed-depth layout -- and lets the type mismatch
propagate exactly as it does for data columns.
Why
KeyErrorand not something widerThe swallowed errors are not one kind. Probing the failure modes against a
string partition value:
==and>against an int raiseArrowNotImplementedError,is_inraisesArrowTypeError, arithmetic raisesTypeError, and an unknown column raisesKeyError.Three of those four are the same user error -- a type mismatch -- wearing
three exception types, so an allowlist of "errors to raise" would be leaky by
construction. The benign case is exactly one type. Narrowing to it is the only
cut that separates them cleanly.
Adding
except Exception: return Trueunderneath would restore the oldbehaviour in full, so it is not a safety net; it is a revert.
What doesn't change
Narrowing only changes behaviour for predicates that previously raised.
Everything that already returned a real answer must return the same one, so
that is asserted directly in
test_evaluate_predicate_on_partition_unaffected_cases: correctly typed==/!=/>, compound&and|over partition columns,is_null,is_in, and a UDF over a partition column -- plus the missing-column case,which is the one thing the narrowed handler still swallows.
All 13 of those pass unchanged against master's
except Exception. Only thetype-mismatch test flips. That A/B is what makes the narrowing defensible.
Test
On this branch: 32 failed, 51 passed. On unmodified master: 32 failed, 37
passed. The same 32 failures either way -- they are pre-existing S3 failures in
my environment -- so the delta is exactly the 14 added tests, and nothing
regressed.
test_evaluate_predicate_on_partition_type_mismatchfails on master withDID NOT RAISE ArrowNotImplementedErrorand passes here.AI assistance was used to write this change.