Repository navigation
Conversation
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]>
There was a problem hiding this comment.
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.
| 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) | ||
| ] |
There was a problem hiding this comment.
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)
]
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 addressesFilteroption preservation or compatibility checks inPredicatePushdown.Before
For a filter such as
ds.filter(expr=(col("id") >= 0) & udf(col("id")), runtime_env=..., num_gpus=1), pushingid >= 0intoReadFiles—or moving the filter pastProject,Sort,Repartition,RandomShuffle, orUnion—rebuilds a defaultFilterand dropscompute,ray_remote_args, andray_remote_args_fn. Consecutive.filter(expr=...)calls also fuse without checking execution-option compatibility, discarding conflicting options.After
Rebind relocated and residual
Filteroperators viadataclasses.replace(clearing position-specificper_block_limitandprocessed_join_conjuncts), and combine any scanner-declined residual fromReadFiles.apply_predicatewith non-convertible conjuncts into a singleFiltercarrying the original options. Gate_try_fuse_filtersonare_op_remote_args_compatibleandFuseOperators._fuse_compute_strategy, retaining the upstream remote args likeFuseOperators.Predicates accepted in full by the reader still push down without leaving a residual
Filter. When aFilterpushes intoUnionbranches, per-operator concurrency caps apply per branch, matchingJoinpushdown.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 changedSubsystems
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.datasources loaded on both driver and workers. Unit and end-to-end tests check fusion compatibility, read and scanner-declined residuals, relocation acrossProject/Sort/Union, and worker-observedruntime_env, CPU allocation, and remote-args callbacks. Static checks (pyrefly0.51.0,ci/lint/pytest_checker.py,black --check,ruff check,git diff --check) also passed.AI assistance was used.