Skip to content

[Data] Raise instead of keeping every file when a partition filter can't be evaluated - #65990

Merged
goutamvenkat-anyscale merged 2 commits into
ray-project:masterfrom
AarryaSaraf:data-fix-partition-filter-fail-open
Sep 9, 2026
Merged

goutamvenkat-anyscale merged 2 commits into
ray-project:masterfrom
AarryaSaraf:data-fix-partition-filter-fail-open

Conversation

@AarryaSaraf

@AarryaSaraf AarryaSaraf commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

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:

# 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.

@AarryaSaraf AarryaSaraf changed the title [Data] Fix partition filter silently keeping every file when it cannot be evaluated [Data] Raise instead of keeping every file when a partition filter can't be evaluated Sep 8, 2026
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 AarryaSaraf added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Sep 8, 2026
@AarryaSaraf
AarryaSaraf force-pushed the data-fix-partition-filter-fail-open branch from 74356b5 to c91d3eb Compare September 8, 2026 23:23
@AarryaSaraf
AarryaSaraf marked this pull request as ready for review September 9, 2026 00:05
@AarryaSaraf
AarryaSaraf requested a review from a team as a code owner September 9, 2026 00:05

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
goutamvenkat-anyscale merged commit 1deb144 into ray-project:master Sep 9, 2026
6 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants