Skip to content

[Data] Fix shuffle v2 failures with reordered columns and empty blocks - #67812

Draft
XiaoHongbo-Hope wants to merge 1 commit into
ray-project:masterfrom
XiaoHongbo-Hope:fix/shuffle-v2-arrow-schema
Draft

XiaoHongbo-Hope wants to merge 1 commit into
ray-project:masterfrom
XiaoHongbo-Hope:fix/shuffle-v2-arrow-schema

Conversation

@XiaoHongbo-Hope

@XiaoHongbo-Hope XiaoHongbo-Hope commented Nov 4, 2026 •

Copy link
Copy Markdown

Shuffle v2 fails when blocks have reordered columns or schema-less empty inputs. This fixes concatenation in reducers and disk map buffers, preserves a non-empty mapper's schema for empty partitions, and skips sorting empty results.

Scope: keyed repartition accepts reordered columns with matching names and types. Type mismatches are rejected within and across mappers; this PR does not add non-key type promotion or cross-mapper schema conversion. Key types are checked before partitions are emitted to avoid splitting equal values across partitions.

Subsystems: Execution; Shuffle / aggregation.

flowchart LR
    A[Validate schemas within mapper] --> B[Partition and concatenate reordered columns]
    B --> C[Validate schemas across mappers]
    C --> D[Emit partitions with typed empties]
Loading

Validation with patched Ray 2.60 (Python 3.11, PyArrow 22):

  • python -m pytest --noconftest -o addopts='' -q python/ray/data/tests/unit/test_hash_shuffle_reducers.py: 62 passed, covering reordered columns, empty inputs, and rejected type changes with both shuffle transports and batching on/off.
  • All 7 affected Paimon regressions passed.
  • pre-commit run and git diff --check passed.

AI-assisted implementation and testing. No matching fix found in the initial shuffle/schema PR search. Draft pending human review.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@XiaoHongbo-Hope XiaoHongbo-Hope changed the title [Data] Fix schema reconciliation in shuffle v2 reducers [Data] Fix shuffle v2 failures with reordered columns and empty blocks Nov 4, 2026
@XiaoHongbo-Hope
XiaoHongbo-Hope force-pushed the fix/shuffle-v2-arrow-schema branch from f5f9850 to 4825966 Compare November 5, 2026 06:44
richardliaw pushed a commit that referenced this pull request Nov 13, 2026
## Summary
`Dataset.sort()` now honors `DataContext.use_disk_based_hash_shuffle`
(`RAY_DATA_ENABLE_DISK_SHUFFLE=1`) under `SHUFFLE_V2`, like keyed
repartition, aggregations, and joins. Off by default.

## Before
Sort ignored the flag. `DiskHashShuffleReduceOp` could only emit
partitions in completion order, and the disk shard writer rejected
compatible but non-identical block schemas (null vs int64).

## After
- Flag on: `SortSamplingOp -> DiskSortShuffleMapOp ->
DiskHashShuffleReduceOp(preserve_partition_order=True)`.
- `DiskHashShuffleReduceOp` gains `preserve_partition_order` (reuses
`ReorderingBundleQueue`); the fusion rule forwards it.
- Boundary resolution moves into `SortRangePartitioner`, shared by
`SortShuffleMapOp` and the new `DiskSortShuffleMapOp`.
- **All disk shuffles:** the shard writer concatenates with
`transform_pyarrow.concat(promote_types=True)`.

```mermaid
flowchart LR
    subgraph Before
        direction TB
        B1[_plan_sort_v2] --> B2[SortShuffleMapOp] --> B3["ShuffleReduceOp (ordered)"]
        B4[DiskHashShuffleMapOp] --> B5["DiskHashShuffleReduceOp (FIFO)"]
    end
    subgraph After
        direction TB
        A1["_plan_sort_v2 (picks transport)"] --> A2[SortShuffleMapOp] --> A3["ShuffleReduceOp (ordered)"]
        A1 --> A4[DiskSortShuffleMapOp] --> A5["DiskHashShuffleReduceOp (ordered or FIFO)"]
        A6[SortRangePartitioner] -.-> A2
        A6 -.-> A4
    end
    Before ~~~ After
    class A4,A6 added
    class A1,A2,A5 changed
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
```

## Benchmark
1 TB sort (1000 x 1 GB partitions, 32 nodes), from a temporary release
entry run on this PR ([build
113798](https://buildkite.com/ray-project/release/builds/113798)) and
reverted since `tpch_*_disk_shuffle` already covers sort on disk.

| | object store | disk |
|---|---|---|
| End-to-end time | 3467 s | 3089 s (-11%) |
| Spilled | 1724 GB / 508k objects | 1486 GB / 2.1k objects |
| Peak driver memory | 1.96 GB | 0.43 GB |

Disk removes the map shards from the object store (the 500k small
spilled objects); the remaining spill is the 1 TB input and materialized
output on a 596 GB object store.

## Subsystems
physical planning, logical planning (fusion rule), execution / shuffle,
docs

## Testing
- `test_sort_shuffle_v2.py test_hash_shuffle_disk_smoke.py
test_hash_shuffle_disk_repartition.py`: 47 passed (sort tests
parametrized over `object_store`/`disk`).
- `test_execution_optimizer_advanced.py test_stats.py -k sort`: 16
passed. `test_sort.py -k shuffle_v2_disk`: 12 passed.
- `pre-commit run` on changed files: clean.

## Notes
- Not a duplicate (`gh pr list --search "disk shuffle sort"`). #67812
touches the same writer concat without type promotion; small rebase for
whichever lands second.
- AI assistance (Claude Code) was used. Every changed line has been
manually reviewed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Sirui Huang <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Nov 19, 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

stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant