Repository navigation
Conversation
…xecution Keep resolved aggregation output column names (_2, _3, ... suffixes and in-place group-key overwrites) consistent across static schema inference, vectorized hash-aggregate finalization, and output-partitioning checks. Also treat non-Count whole-row AggregateFnV2(on=None) aggregations as requiring all input columns so projection pushdown preserves non-key inputs once suffixed outputs resolve statically. Closes ray-project#68629 Signed-off-by: mora <[email protected]>
Contributor
There was a problem hiding this comment.
Code Review
This pull request standardizes and fixes aggregation column name resolution across schema inference, execution, and planning by utilizing _resolve_aggregated_column_names. This ensures that schema inference matches the actual output column names during execution, particularly when handling name collisions and key overwrites. Comprehensive unit tests have been added to verify these changes. I have no feedback to provide as there are no review comments.
This branch has not been deployed
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.
Summary
Keep
ds.groupby(...).aggregate(...)output column names (_2,_3, ... suffixes and in-place group-key overwrites) consistent across schema inference, vectorized hash-shuffle finalization, and shuffle elimination, closing #68629. This extends #66218's block-level aggregation name resolution to logical planning and default hash-shuffle execution.Before
When
ds.groupby(...).aggregate(...)produces duplicate output names—such asQuantile("v", q=0.25), Quantile("v", q=0.75)—or overwrites a group key on Arrow-backed inputs,ds.schema()andds.columns()infer unsuffixed duplicates or duplicate key fields, causingwith_column()to drop suffixed columns anddrop_columns()to fail when targeting those names. In default hash-shuffle execution, collision chains like["a", "a_2", "a"]also overwritea_2instead of producinga_3, and overwriting a group key with a suffixed column leaves stale partitioning metadata that can skip the shuffle in a subsequentgroupby().After
Apply the shared aggregation column-name resolver across logical schema inference, vectorized hash-aggregate finalization, and output-partitioning checks, replacing overwritten group-key fields in place and clearing hash-partitioning metadata whenever any resolved output name matches a group key. Also treat non-
Countwhole-rowAggregateFnV2(on=None)aggregations as requiring all input columns so projection pushdown preserves non-key inputs once suffixed outputs resolve statically.Non-Arrow input schemas and aggregations without a static output type (such as
Uniqueon nested columns,Quantileon strings, or default legacyAggregateFn) remain statically unresolved and use the existing execution fallback;Count()continues allowing input pruning to non-empty group keys, and legacy hash/sort shuffle planners remain unchanged.flowchart LR subgraph Before B1["Logical / Physical planning & Shuffle (separate naming)"] -. desyncs suffixes & key overwrites .-> B2["Dropped _2 columns, overwritten aliases & skipped re-shuffle"] end subgraph After A1["Logical / Physical planning & Shuffle (shared name resolver)"] -. aligns Arrow schema, finalize & partitioning .-> A2["Preserved _2.._N columns, intact aliases & valid re-shuffle"] end classDef bad fill:#ffcdd2,stroke:#c62828,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 classDef good fill:#c8e6c9,stroke:#2e7d32,color:#000 class B1,B2 bad class A1 changed class A2 goodSubsystems
Logical planning / query optimization, Physical planning, and Shuffle / aggregation.
Testing
Local validation passed on Python 3.11.15 / Ray 3.0.0.dev0 (
a872863f2b, PyArrow 26.0.1, pandas 2.3.3) with the updatedray.datasources loaded on both driver and workers. Tests check static schema inference, downstreamwith_column/drop_columns/select_columnspruning, whole-rowAggregateFnV2(on=None)column retention,["a", "a_2", "a"]collision chains across shuffle strategies, and partition invalidation on suffixed key overwrites.Pre-commit hooks (including
pyrefly-data) and pytest lint checks also passed.AI assistance was used.