Repository navigation
[Data] Fix hash-shuffle aggregator memory estimation: metadata propagation, node-size clamp, and column pruning - #63809
Conversation
…stimate When projection pushdown places a Project between a read and a join, the join's input logical op becomes a Project. Project inherited the base all-None infer_metadata, so _try_estimate_output_bytes saw size_bytes=None and the HashShuffleAggregator silently fell back to a fixed default memory reservation (1 GiB/aggregator) instead of one derived from the dataset size (~5.3 GiB for TPCH Q3 SF100). On an autoscaling cluster this under-provisions the aggregators and OOM-kills the worker mid-join. Add infer_metadata to AbstractOneToOne that propagates num_rows, size_bytes, and input_files from its single input dependency, gated on can_modify_num_rows: row-preserving ops (e.g. Project) propagate the input's estimates (an upper bound for column selection), while row-modifying ops (e.g. Filter, FlatMap) fall back to None. Limit keeps its own override. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Goutam <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements an infer_metadata method in OneToOneOperator to propagate metadata (such as num_rows and size_bytes) from the input dependency when the operator does not modify the row count. The reviewer noted that propagating size_bytes is incorrect for operators like Download because they do not modify the row count but significantly increase the data size, which could lead to downstream memory under-estimation and potential OOMs. A code suggestion was provided to exclude Download from propagating size_bytes.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Download is row-preserving (can_modify_num_rows=False), so the new AbstractOneToOne.infer_metadata would propagate the input's size_bytes. But Download appends a binary blob column per output, so the output is much larger than the input -- propagating the input size is a misleading under-estimate that could starve downstream size-dependent planning. Override Download.infer_metadata to keep the accurate row count and input files but report size_bytes=None, since the downloaded byte volume can't be estimated ahead of execution. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Goutam <[email protected]>
Making input size estimates available more often (via metadata propagation through one-to-one ops) means the hash-shuffle/aggregate memory estimate now fires in cases where it previously fell back to a small default. For a low-partition shuffle over a large dataset -- e.g. a global aggregation with num_partitions=1 -- the estimate reserves ~2x the whole dataset as a single aggregator's `memory` request, which exceeds any node and makes the actor unschedulable (ActorUnschedulableError). Clamp the per-aggregator memory reservation to the largest single node's memory. Aggregators hold shuffle data in the (spillable) object store, so reserving more heap `memory` than a node has only makes the actor unschedulable, not faster; clamping lets it schedule and spill instead. The clamp only triggers when the estimate exceeds node capacity, so well-sized reservations are unaffected. Logs a warning when it engages. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Goutam <[email protected]>
An Aggregate only reads its group keys and each aggregation's target column; every other column is dropped by the aggregation anyway. But nothing pruned them before the shuffle, so wide unused columns (e.g. a string column carried through by with_column) were dragged through the aggregator -- inflating both its memory reservation and the bytes shuffled. Extend ProjectionPushdown to insert a pruning Project below an Aggregate that keeps only the consumed columns (keys + aggregation targets); the existing fuse/push steps then carry the narrowed set into the read. The insertion only fires when the input schema is known and has columns beyond the required set, which keeps the fixed-point optimizer idempotent. Aggregations whose target columns can't be determined (generic AggregateFn) are left untouched. Add a parameterized test covering group-by sum, multi-aggregation, a computed aggregation column, and count. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: Goutam <[email protected]>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces projection pushdown optimizations and memory reservation clamping for shuffles in Ray Data. Specifically, it implements input pruning for Aggregate operators to avoid dragging unused columns through shuffles, propagates metadata in OneToOneOperator to improve size-dependent planning, and clamps per-aggregator memory requests to the maximum single-node memory capacity to prevent unschedulable actors. The review feedback points out a potential bug in _prune_aggregate_input where checking if op.key can incorrectly discard valid falsy column names (such as 0 or ""), and suggests explicitly checking op.key is not None instead.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if not isinstance(op, Aggregate): | ||
| return op | ||
|
|
||
| keys = op.key if isinstance(op.key, list) else ([op.key] if op.key else []) |
There was a problem hiding this comment.
Using if op.key to check for the presence of a group key can lead to incorrect pruning and subsequent KeyErrors if the group key is a falsy value, such as the integer 0 or an empty string "" (both of which are valid column names in Pandas/PyArrow). Explicitly check if op.key is not None to ensure falsy but valid column names are preserved.
| keys = op.key if isinstance(op.key, list) else ([op.key] if op.key else []) | |
| keys = op.key if isinstance(op.key, list) else ([op.key] if op.key is not None else []) |
…ation, node-size clamp, and column pruning (ray-project#63809) ## Description The hash-shuffle/join/aggregate operators size each aggregator's `memory` reservation from the estimated input dataset size. That estimate was both **missing** in some plans (causing under-reservation → OOM) and **over-counted** in others (causing over-reservation → unschedulable). This PR makes the estimate available, accurate, and bounded. ### Triggering change This was surfaced by **ray-project#63384 ([Data] Remove column renaming from the read stage)**. Before that PR the read stage performed column renames inline, so a TPCH plan looked like `ReadParquet → Join` with no intervening op. ray-project#63384 moved renames out of the read into a separate `Project` (of `AliasExpr`s) above the read, so the plan became `ReadParquet → Project → Join`. That exposed a latent gap: `Project.infer_metadata` returned all-`None`, so once a `Project` sat between a read and a join/aggregate the size estimate disappeared and the aggregator fell back to a fixed default reservation — which under-provisioned the TPCH Q3 autoscaling release test and OOM-killed it. The changes below fix that latent gap and the issues uncovered while fixing it. ### 1. Propagate metadata through one-to-one ops (fixes join OOM) With a rename `Project` now between the read and the join, the join's input op was a `Project`, which inherited the base all-`None` `infer_metadata`. So `_try_estimate_output_bytes` saw `size_bytes=None` and the `HashShuffleAggregator` silently fell back to a fixed default (`DEFAULT_HASH_SHUFFLE_AGGREGATOR_MEMORY_ALLOCATION`, 1 GiB/aggregator) instead of a size-derived reservation (~5.3 GiB/aggregator for TPCH Q3 SF100). On an autoscaling cluster this under-provisions the aggregators and the worker is OOM-killed mid-join (`ActorDiedError` / `SYSTEM_ERROR: Worker connection closed unexpectedly`). `AbstractOneToOne.infer_metadata` now propagates `num_rows`/`size_bytes`/`input_files` from its single input, gated on `can_modify_num_rows` (row-preserving ops like `Project` propagate; `Filter`/`FlatMap` fall back to `None`). `Download` overrides this to report `size_bytes=None`, since it appends blob columns and the input size would be a misleading under-estimate. ### 2. Prune unused columns before hash-shuffle aggregations An `Aggregate` only reads its group keys and each aggregation's target column, but nothing pruned the rest before the shuffle — so wide unused columns (e.g. a string column carried through by `with_column`) were dragged through the aggregator, inflating both its memory reservation and the bytes shuffled. `ProjectionPushdown` now inserts a pruning `Project` below an `Aggregate` keeping only the consumed columns (keys + aggregation targets); the existing fuse/push steps carry the narrowed set into the read. It only fires when the input schema is known and has extra columns (keeping the fixed-point optimizer idempotent), and leaves generic `AggregateFn`s (unknown columns) untouched. ### 3. Clamp the aggregator reservation to the largest node (safety net) With estimates now firing more often, a low-partition shuffle over a large dataset (e.g. a global aggregation with `num_partitions=1`) could reserve ~2× the whole dataset as a single aggregator's `memory` request — exceeding any node and making the actor unschedulable (`ActorUnschedulableError`). The per-aggregator reservation is now clamped to the largest single node's memory: aggregators hold shuffle data in the (spillable) object store, so reserving more heap `memory` than a node has only makes the actor unschedulable, not faster. The clamp only triggers when the estimate exceeds node capacity (well-sized reservations are unaffected) and logs a warning when it engages. ## Verification - Join estimate restored through a plan with a `Project` between the read and the join (was `None` → 1 GiB fallback). - Q6-shaped global aggregation: read is pruned to the consumed columns; end-to-end result matches a pandas ground truth. - Clamp engages only when the estimate exceeds node memory and the run completes via spilling. - Correctness validated across combos (filters, group-by, multi-aggregation, post-shuffle join→aggregate, computed columns) by comparing pruned vs unpruned pipelines. - New parameterized tests in `test_projection_fusion.py` (aggregate input pruning) and existing suites pass (`test_projection_fusion`, `test_predicate_pushdown`, `test_execution_optimizer_basic`, `test_infer_schema`, aggregation tests). ## Related issues Surfaced by ray-project#63384 (column renames moved out of the read stage into a `Project`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ation, node-size clamp, and column pruning (ray-project#63809) ## Description The hash-shuffle/join/aggregate operators size each aggregator's `memory` reservation from the estimated input dataset size. That estimate was both **missing** in some plans (causing under-reservation → OOM) and **over-counted** in others (causing over-reservation → unschedulable). This PR makes the estimate available, accurate, and bounded. ### Triggering change This was surfaced by **ray-project#63384 ([Data] Remove column renaming from the read stage)**. Before that PR the read stage performed column renames inline, so a TPCH plan looked like `ReadParquet → Join` with no intervening op. ray-project#63384 moved renames out of the read into a separate `Project` (of `AliasExpr`s) above the read, so the plan became `ReadParquet → Project → Join`. That exposed a latent gap: `Project.infer_metadata` returned all-`None`, so once a `Project` sat between a read and a join/aggregate the size estimate disappeared and the aggregator fell back to a fixed default reservation — which under-provisioned the TPCH Q3 autoscaling release test and OOM-killed it. The changes below fix that latent gap and the issues uncovered while fixing it. ### 1. Propagate metadata through one-to-one ops (fixes join OOM) With a rename `Project` now between the read and the join, the join's input op was a `Project`, which inherited the base all-`None` `infer_metadata`. So `_try_estimate_output_bytes` saw `size_bytes=None` and the `HashShuffleAggregator` silently fell back to a fixed default (`DEFAULT_HASH_SHUFFLE_AGGREGATOR_MEMORY_ALLOCATION`, 1 GiB/aggregator) instead of a size-derived reservation (~5.3 GiB/aggregator for TPCH Q3 SF100). On an autoscaling cluster this under-provisions the aggregators and the worker is OOM-killed mid-join (`ActorDiedError` / `SYSTEM_ERROR: Worker connection closed unexpectedly`). `AbstractOneToOne.infer_metadata` now propagates `num_rows`/`size_bytes`/`input_files` from its single input, gated on `can_modify_num_rows` (row-preserving ops like `Project` propagate; `Filter`/`FlatMap` fall back to `None`). `Download` overrides this to report `size_bytes=None`, since it appends blob columns and the input size would be a misleading under-estimate. ### 2. Prune unused columns before hash-shuffle aggregations An `Aggregate` only reads its group keys and each aggregation's target column, but nothing pruned the rest before the shuffle — so wide unused columns (e.g. a string column carried through by `with_column`) were dragged through the aggregator, inflating both its memory reservation and the bytes shuffled. `ProjectionPushdown` now inserts a pruning `Project` below an `Aggregate` keeping only the consumed columns (keys + aggregation targets); the existing fuse/push steps carry the narrowed set into the read. It only fires when the input schema is known and has extra columns (keeping the fixed-point optimizer idempotent), and leaves generic `AggregateFn`s (unknown columns) untouched. ### 3. Clamp the aggregator reservation to the largest node (safety net) With estimates now firing more often, a low-partition shuffle over a large dataset (e.g. a global aggregation with `num_partitions=1`) could reserve ~2× the whole dataset as a single aggregator's `memory` request — exceeding any node and making the actor unschedulable (`ActorUnschedulableError`). The per-aggregator reservation is now clamped to the largest single node's memory: aggregators hold shuffle data in the (spillable) object store, so reserving more heap `memory` than a node has only makes the actor unschedulable, not faster. The clamp only triggers when the estimate exceeds node capacity (well-sized reservations are unaffected) and logs a warning when it engages. ## Verification - Join estimate restored through a plan with a `Project` between the read and the join (was `None` → 1 GiB fallback). - Q6-shaped global aggregation: read is pruned to the consumed columns; end-to-end result matches a pandas ground truth. - Clamp engages only when the estimate exceeds node memory and the run completes via spilling. - Correctness validated across combos (filters, group-by, multi-aggregation, post-shuffle join→aggregate, computed columns) by comparing pruned vs unpruned pipelines. - New parameterized tests in `test_projection_fusion.py` (aggregate input pruning) and existing suites pass (`test_projection_fusion`, `test_predicate_pushdown`, `test_execution_optimizer_basic`, `test_infer_schema`, aggregation tests). ## Related issues Surfaced by ray-project#63384 (column renames moved out of the read stage into a `Project`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
…ation, node-size clamp, and column pruning (ray-project#63809) ## Description The hash-shuffle/join/aggregate operators size each aggregator's `memory` reservation from the estimated input dataset size. That estimate was both **missing** in some plans (causing under-reservation → OOM) and **over-counted** in others (causing over-reservation → unschedulable). This PR makes the estimate available, accurate, and bounded. ### Triggering change This was surfaced by **ray-project#63384 ([Data] Remove column renaming from the read stage)**. Before that PR the read stage performed column renames inline, so a TPCH plan looked like `ReadParquet → Join` with no intervening op. ray-project#63384 moved renames out of the read into a separate `Project` (of `AliasExpr`s) above the read, so the plan became `ReadParquet → Project → Join`. That exposed a latent gap: `Project.infer_metadata` returned all-`None`, so once a `Project` sat between a read and a join/aggregate the size estimate disappeared and the aggregator fell back to a fixed default reservation — which under-provisioned the TPCH Q3 autoscaling release test and OOM-killed it. The changes below fix that latent gap and the issues uncovered while fixing it. ### 1. Propagate metadata through one-to-one ops (fixes join OOM) With a rename `Project` now between the read and the join, the join's input op was a `Project`, which inherited the base all-`None` `infer_metadata`. So `_try_estimate_output_bytes` saw `size_bytes=None` and the `HashShuffleAggregator` silently fell back to a fixed default (`DEFAULT_HASH_SHUFFLE_AGGREGATOR_MEMORY_ALLOCATION`, 1 GiB/aggregator) instead of a size-derived reservation (~5.3 GiB/aggregator for TPCH Q3 SF100). On an autoscaling cluster this under-provisions the aggregators and the worker is OOM-killed mid-join (`ActorDiedError` / `SYSTEM_ERROR: Worker connection closed unexpectedly`). `AbstractOneToOne.infer_metadata` now propagates `num_rows`/`size_bytes`/`input_files` from its single input, gated on `can_modify_num_rows` (row-preserving ops like `Project` propagate; `Filter`/`FlatMap` fall back to `None`). `Download` overrides this to report `size_bytes=None`, since it appends blob columns and the input size would be a misleading under-estimate. ### 2. Prune unused columns before hash-shuffle aggregations An `Aggregate` only reads its group keys and each aggregation's target column, but nothing pruned the rest before the shuffle — so wide unused columns (e.g. a string column carried through by `with_column`) were dragged through the aggregator, inflating both its memory reservation and the bytes shuffled. `ProjectionPushdown` now inserts a pruning `Project` below an `Aggregate` keeping only the consumed columns (keys + aggregation targets); the existing fuse/push steps carry the narrowed set into the read. It only fires when the input schema is known and has extra columns (keeping the fixed-point optimizer idempotent), and leaves generic `AggregateFn`s (unknown columns) untouched. ### 3. Clamp the aggregator reservation to the largest node (safety net) With estimates now firing more often, a low-partition shuffle over a large dataset (e.g. a global aggregation with `num_partitions=1`) could reserve ~2× the whole dataset as a single aggregator's `memory` request — exceeding any node and making the actor unschedulable (`ActorUnschedulableError`). The per-aggregator reservation is now clamped to the largest single node's memory: aggregators hold shuffle data in the (spillable) object store, so reserving more heap `memory` than a node has only makes the actor unschedulable, not faster. The clamp only triggers when the estimate exceeds node capacity (well-sized reservations are unaffected) and logs a warning when it engages. ## Verification - Join estimate restored through a plan with a `Project` between the read and the join (was `None` → 1 GiB fallback). - Q6-shaped global aggregation: read is pruned to the consumed columns; end-to-end result matches a pandas ground truth. - Clamp engages only when the estimate exceeds node memory and the run completes via spilling. - Correctness validated across combos (filters, group-by, multi-aggregation, post-shuffle join→aggregate, computed columns) by comparing pruned vs unpruned pipelines. - New parameterized tests in `test_projection_fusion.py` (aggregate input pruning) and existing suites pass (`test_projection_fusion`, `test_predicate_pushdown`, `test_execution_optimizer_basic`, `test_infer_schema`, aggregation tests). ## Related issues Surfaced by ray-project#63384 (column renames moved out of the read stage into a `Project`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Goutam <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: 400Ping <[email protected]>
Description
The hash-shuffle/join/aggregate operators size each aggregator's
memoryreservation from the estimated input dataset size. That estimate was both missing in some plans (causing under-reservation → OOM) and over-counted in others (causing over-reservation → unschedulable). This PR makes the estimate available, accurate, and bounded.Triggering change
This was surfaced by #63384 ([Data] Remove column renaming from the read stage). Before that PR the read stage performed column renames inline, so a TPCH plan looked like
ReadParquet → Joinwith no intervening op. #63384 moved renames out of the read into a separateProject(ofAliasExprs) above the read, so the plan becameReadParquet → Project → Join. That exposed a latent gap:Project.infer_metadatareturned all-None, so once aProjectsat between a read and a join/aggregate the size estimate disappeared and the aggregator fell back to a fixed default reservation — which under-provisioned the TPCH Q3 autoscaling release test and OOM-killed it. The changes below fix that latent gap and the issues uncovered while fixing it.1. Propagate metadata through one-to-one ops (fixes join OOM)
With a rename
Projectnow between the read and the join, the join's input op was aProject, which inherited the base all-Noneinfer_metadata. So_try_estimate_output_bytessawsize_bytes=Noneand theHashShuffleAggregatorsilently fell back to a fixed default (DEFAULT_HASH_SHUFFLE_AGGREGATOR_MEMORY_ALLOCATION, 1 GiB/aggregator) instead of a size-derived reservation (~5.3 GiB/aggregator for TPCH Q3 SF100). On an autoscaling cluster this under-provisions the aggregators and the worker is OOM-killed mid-join (ActorDiedError/SYSTEM_ERROR: Worker connection closed unexpectedly).AbstractOneToOne.infer_metadatanow propagatesnum_rows/size_bytes/input_filesfrom its single input, gated oncan_modify_num_rows(row-preserving ops likeProjectpropagate;Filter/FlatMapfall back toNone).Downloadoverrides this to reportsize_bytes=None, since it appends blob columns and the input size would be a misleading under-estimate.2. Prune unused columns before hash-shuffle aggregations
An
Aggregateonly reads its group keys and each aggregation's target column, but nothing pruned the rest before the shuffle — so wide unused columns (e.g. a string column carried through bywith_column) were dragged through the aggregator, inflating both its memory reservation and the bytes shuffled.ProjectionPushdownnow inserts a pruningProjectbelow anAggregatekeeping only the consumed columns (keys + aggregation targets); the existing fuse/push steps carry the narrowed set into the read. It only fires when the input schema is known and has extra columns (keeping the fixed-point optimizer idempotent), and leaves genericAggregateFns (unknown columns) untouched.3. Clamp the aggregator reservation to the largest node (safety net)
With estimates now firing more often, a low-partition shuffle over a large dataset (e.g. a global aggregation with
num_partitions=1) could reserve ~2× the whole dataset as a single aggregator'smemoryrequest — exceeding any node and making the actor unschedulable (ActorUnschedulableError). The per-aggregator reservation is now clamped to the largest single node's memory: aggregators hold shuffle data in the (spillable) object store, so reserving more heapmemorythan a node has only makes the actor unschedulable, not faster. The clamp only triggers when the estimate exceeds node capacity (well-sized reservations are unaffected) and logs a warning when it engages.Verification
Projectbetween the read and the join (wasNone→ 1 GiB fallback).test_projection_fusion.py(aggregate input pruning) and existing suites pass (test_projection_fusion,test_predicate_pushdown,test_execution_optimizer_basic,test_infer_schema, aggregation tests).Related issues
Surfaced by #63384 (column renames moved out of the read stage into a
Project).🤖 Generated with Claude Code