Skip to content

[Data] Preserve datasource V2 ordering at execution time - #68650

Open
viiccwen wants to merge 2 commits into
ray-project:masterfrom
viiccwen:feat/preserve-order-execution-config
Open

viiccwen wants to merge 2 commits into
ray-project:masterfrom
viiccwen:feat/preserve-order-execution-config

Conversation

@viiccwen

@viiccwen viiccwen commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fix datasource V2 reads that can reorder files or chunks despite preserve_order=True. Resolve effective ordering before physical planning and pass it explicitly to file partitioners, including ordering required by zip().

Related issues

Fixes #68649.
Fixes #68648.
Fixes #68646.

Before

CSV, Text, and WebDataset selected their bucket count when the datasource was constructed; MCAP read ordering from the current global context during ingestion. Parquet's bin packer could reorder files and row groups within manifests. Ordering required by zip() was enabled after planning, too late for listing and partitioning to use it.

After

Dataset._execute_dag() resolves ordering before planning. Each listing task calls FilePartitioner.start(preserve_order=...) before its first manifest. RoundRobin uses one bucket for ordered reads; OnlineBinPacker uses next-fit packing and merges only adjacent, ascending runs of the same file. Both packing modes share manifest construction, and repeated paths retain their multiplicity.

Data flow

flowchart TD
    subgraph Before
        subgraph BAPI["API: Dataset"]
            B1["_execute_dag: plan before enforcing ordering"]
        end
        subgraph BPlanning["Physical planning: ListFiles"]
            B2["Capture ordering before it is enforced"]
        end
        subgraph BIO["IO: datasource V2"]
            B3["Partitioners use early, global, or default ordering"]
            B4["ReadFiles consumes regrouped manifest rows"]
        end
        B1 --> B2 --> B3 --> B4
    end
    subgraph After
        subgraph AAPI["API: Dataset"]
            A1["_execute_dag: resolve ordering before planning"]
        end
        subgraph APlanning["Physical planning: ListFiles"]
            A2["Capture effective ordering"]
        end
        subgraph AIO["IO: datasource V2"]
            A3["partition_files: FilePartitioner.start"]
            A4["Partitioners retain listing and unit order"]
            A5["ReadFiles consumes ordered manifest rows"]
        end
        A1 --> A2 --> A3 --> A4 --> A5
    end
    classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    class A3 added
    class B1,B2,B3,A1,A2,A4 changed
Loading

Resolve effective ordering before physical planning and configure file partitioners at listing-task start. Keep ordered manifest rows in listing order while preserving duplicate reads and non-ordered packing.

Signed-off-by: viiccwen <[email protected]>
@viiccwen
viiccwen requested review from a team as code owners November 29, 2026 11:42

@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 refactors order preservation in Ray Data's V2 datasources by introducing a start(preserve_order=...) method to the FilePartitioner interface, allowing partitioners to initialize their ordering strategy before processing inputs. This ensures correct behavior when order preservation is enabled after a read operation. The feedback highlights a potential IndexError in OnlineBinPacker if unit_ids is empty, and a missing datasource_v2 parameterization decorator on a new Parquet test.

Keep empty read-unit runs as separate manifest rows instead of indexing their empty unit ID tuples. Extend the existing ordering test with empty runs before and after non-empty runs.

Signed-off-by: viiccwen <[email protected]>
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 29, 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

1 participant