Skip to content

[Data] Preserve Filter execution options across predicate pushdown - #68625

Open
m4ru1 wants to merge 1 commit into
ray-project:masterfrom
m4ru1:fix/predicate-pushdown-filter-options
Open

m4ru1 wants to merge 1 commit into
ray-project:masterfrom
m4ru1:fix/predicate-pushdown-filter-options

Conversation

@m4ru1

@m4ru1 m4ru1 commented Nov 28, 2026

Copy link
Copy Markdown

Summary

Preserve Dataset.filter(expr=...) execution options during predicate pushdown and only fuse consecutive expression filters when their options are compatible, closing #68624. No existing issue or open PR addresses Filter option preservation or compatibility checks in PredicatePushdown.

Before

For a filter such as ds.filter(expr=(col("id") >= 0) & udf(col("id")), runtime_env=..., num_gpus=1), pushing id >= 0 into ReadFiles—or moving the filter past Project, Sort, Repartition, RandomShuffle, or Union—rebuilds a default Filter and drops compute, ray_remote_args, and ray_remote_args_fn. Consecutive .filter(expr=...) calls also fuse without checking execution-option compatibility, discarding conflicting options.

After

Rebind relocated and residual Filter operators via dataclasses.replace (clearing position-specific per_block_limit and processed_join_conjuncts), and combine any scanner-declined residual from ReadFiles.apply_predicate with non-convertible conjuncts into a single Filter carrying the original options. Gate _try_fuse_filters on are_op_remote_args_compatible and FuseOperators._fuse_compute_strategy, retaining the upstream remote args like FuseOperators.

Predicates accepted in full by the reader still push down without leaving a residual Filter. When a Filter pushes into Union branches, per-operator concurrency caps apply per branch, matching Join pushdown.

flowchart LR
  subgraph Before
    B1["ReadFiles(id >= 0)"] --> B2["Filter(udf, default opts)"]
  end
  subgraph After
    A1["ReadFiles(id >= 0)"] --> A2["Filter(udf, opts)"]
  end
  classDef removed fill:#ffcdd2,stroke:#c62828,color:#000
  classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
  class B2 removed
  class A2 changed
Loading

Subsystems

Logical planning / query optimization.

Testing

Local validation passed on Python 3.13.5, PyArrow 26.0.1, and pandas 2.3.3 using the Ray 2.60.1 wheel with the updated ray.data sources loaded on both driver and workers. Unit and end-to-end tests check fusion compatibility, read and scanner-declined residuals, relocation across Project/Sort/Union, and worker-observed runtime_env, CPU allocation, and remote-args callbacks. Static checks (pyrefly 0.51.0, ci/lint/pytest_checker.py, black --check, ruff check, git diff --check) also passed.

for test in unit/test_predicate_pushdown.py unit/test_ruleset.py \
  test_predicate_pushdown.py test_idempotency_optimizer_guards.py
do
  python -m pytest -q "python/ray/data/tests/$test" || exit 1
done

AI assistance was used.

Clone split, relocated, and branch-pushed Filter operators with
dataclasses.replace so compute, ray_remote_args, and ray_remote_args_fn
survive predicate pushdown, and merge scanner-declined residuals from
ReadFiles.apply_predicate into the same Filter. Check remote-arg and
compute-strategy compatibility before fusing consecutive expression
filters.

Closes ray-project#68624

Signed-off-by: mora <[email protected]>

@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 ensures that execution options (such as compute strategies and remote arguments) are preserved when filters are fused, relocated, or pushed down in the query optimizer. It introduces a helper method _rebind_filter to reset position-specific optimizer state while keeping execution options, and adds comprehensive unit and integration tests to verify this behavior. A review comment suggests making the resource-copying logic in _try_fuse_filters more robust to prevent potential AttributeError exceptions when ray_remote_args or its resources key is None.

Comment on lines +120 to +131
compatibility_ops = [
replace(
filter_op,
ray_remote_args={
**filter_op.ray_remote_args,
"resources": filter_op.ray_remote_args["resources"].copy(),
},
)
if "resources" in filter_op.ray_remote_args
else filter_op
for filter_op in (input_op, op)
]

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.

medium

The check "resources" in filter_op.ray_remote_args can lead to an AttributeError if filter_op.ray_remote_args is None, or if "resources" is present but its value is None (e.g., ray_remote_args={"resources": None}). To make this more robust and prevent potential runtime crashes, we should defensively check that ray_remote_args is not None and that the "resources" key maps to a dictionary before attempting to call .copy() on it.

        compatibility_ops = [
            replace(
                filter_op,
                ray_remote_args={
                    **filter_op.ray_remote_args,
                    "resources": filter_op.ray_remote_args["resources"].copy(),
                },
            )
            if filter_op.ray_remote_args
            and isinstance(filter_op.ray_remote_args.get("resources"), dict)
            else filter_op
            for filter_op in (input_op, op)
        ]

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 28, 2026

This branch has not been deployed

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

Labels

community-contribution Contributed by the community data Ray Data-related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant