Skip to content

[Data] Add configurable path column names to read_parquet - #66572

Open
jiangxt2 wants to merge 18 commits into
ray-project:masterfrom
jiangxt2:fix/issue-63757-configurable-path-column
Open

jiangxt2 wants to merge 18 commits into
ray-project:masterfrom
jiangxt2:fix/issue-63757-configurable-path-column

Conversation

@jiangxt2

@jiangxt2 jiangxt2 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

Before: DataSourceV2 uses a fixed path column; projection can return a same-named file column, and incompatible physical types can cause schema merging to fail.

After: DataSourceV2 callers can choose the synthesized path column name in read_parquet by passing a nonempty string to include_paths, for example ray.data.read_parquet(path, include_paths="source_file"). The synthesized column overwrites a same-named file column, including when projected, and the inferred schema order matches emitted tables.

Nonempty string names require DataSourceV2; V1 rejects them with NotImplementedError instead of silently using path. Boolean usage remains supported.

Reject non-default path names that conflict with partition columns or an enabled row_hash column. Path column names must also remain distinct from active checkpoint-generated ID columns.

Ignore overwritten path fields when merging file schemas, while retaining errors for incompatible types in other fields.

Related issues

Related to #63757
This PR adds configurable Parquet path-column names; #67079 separately addresses synthesized-column filtering.

Additional information

The change is limited to Parquet DataSourceV2 and shared synthesized-column reader behavior; other public file-reading API signatures are unchanged.

DeveloperAPI compatibility: subclasses of PathColumn that previously overrode the name class attribute and used a no-argument constructor must pass the name explicitly or adapt their constructor.

The API shape follows maintainer feedback in #63758 to accept the name through include_paths, and builds on the shared SynthesizedColumn abstraction from #66390.

The upstream synthesized-column filtering fix (#67079) keeps path predicates as residual filters, evaluated after path synthesis.

Subsystems

API (read_api.py) and IO (_internal/datasource_v2/).

Data flow

flowchart LR
    A["API: read_parquet"] --> B["IO: infer file schemas"]
    B --> C["Exclude overwritten path field"]
    C --> D["Merge and augment schema"]
    D --> E["IO: read file columns"]
    E --> F["Append synthesized path"]
Loading

Testing

Latest validation:

  • The custom-path test below passed all 4 cases on Linux ARM64,
    Python 3.12.14 and PyArrow 23.0.1.
  • Applicable pre-commit hooks passed; Pyrefly reported 0 errors on
    its 8-file cumulative scope.

Regression coverage:

The list describes coverage in the suite; only the pytest command below
was rerun against the current code state.

Unless otherwise noted, test names below use the test_read_parquet_v2_ prefix:

  • include_paths catches failed default-path replacement across incompatible
    physical types; custom_path_column_preserves_file_column catches incorrect
    custom paths or filters, schema merge failures and loss of the physical path.
  • path_overrides_only_file_column: catches lost rows when no physical
    columns remain.
  • path_does_not_hide_other_schema_conflicts: catches suppression of type errors in non-overwritten fields.
  • test_read_parquet_v2_rejects_invalid_columns catches acceptance of empty
    names or row-hash conflicts; test_read_parquet_v1_rejects_new_params catches
    V1 accepting a string name; test_custom_path_column_rejects_partition_name
    catches partition conflicts during scanner creation and reading.
  • test_include_paths_with_column_projection catches loss of the default
    path with columns=; test_include_row_hash_existing_column_with_projection
    catches schema/batch order mismatches or changed projected hashes.
  • test_read_parquet_adds_generated_id_column catches missing custom paths
    or invalid generated IDs; test_read_parquet_path_conflicts_with_generated_id
    catches accepted ID-name conflicts, with configuration before and after reading.
  • test_merge_file_schemas_transforms_before_merging: checks that the transform runs before merging and preserves schema metadata.
  • test_push_filters_retains_synthesized_residual: catches failure to retain
    synthesized-column predicates as residual filters.

The retained tests do not cover transform forwarding on the distributed full-schema path.

Command for the 4 passing cases

Run inside the Linux ARM64 container, with the worktree mounted at
/worktree and test dependencies on PYTHONPATH=/deps:

/runtime/venv/bin/python -m pytest -q --rootdir=/worktree \
  --confcutdir=/worktree/python/ray/data -c /worktree/pytest.ini \
  -o cache_dir=/tmp/pytest-cache --junitxml=/evidence/cast-validation.xml \
  /worktree/python/ray/data/tests/datasource/test_read_parquet_v2.py::test_read_parquet_v2_custom_path_column_preserves_file_column \
  2>&1 | tee /evidence/cast-validation.log

Codex and Claude AI assistance was used to implement and validate this change.

@jiangxt2
jiangxt2 marked this pull request as ready for review September 30, 2026 13:11
@jiangxt2
jiangxt2 requested a review from a team as a code owner September 30, 2026 13:11

@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 introduces support for custom path column names when using include_paths with DataSourceV2 in Ray Data. It allows include_paths to accept a string representing the custom column name, updates the PathColumn class to support this name, and adds validation to prevent conflicts with partition columns or row_hash. Additionally, it updates read_parquet and includes comprehensive unit tests. The review feedback highlights a potential schema mismatch if RowHashColumn collides with an existing file column, suggesting that the reordering logic applied to PathColumn should also be extended to RowHashColumn.

@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Sep 30, 2026
@AarryaSaraf AarryaSaraf self-assigned this Oct 1, 2026
Preserve full-schema inference and projection coverage while rejecting
custom path names that collide with generated checkpoint ID columns.

Signed-off-by: jiangxt2 <[email protected]>
Limit the documented rejection rules to non-default custom path names.

Signed-off-by: jiangxt2 <[email protected]>
Preserve custom Parquet path columns while adopting plan-time
checkpoint generated ID binding and its collision validation.

Signed-off-by: jiangxt2 <[email protected]>
@jiangxt2
jiangxt2 marked this pull request as draft October 27, 2026 14:23
Preserve upstream columns validation and filesystem retries alongside
custom Parquet path column projection and checkpoint coverage.

Signed-off-by: jiangxt2 <[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 11, 2026
Preserve custom path collision checks while adopting upstream
partition value helpers for file readers.

Signed-off-by: jiangxt2 <[email protected]>
@jiangxt2
jiangxt2 marked this pull request as ready for review November 11, 2026 03:21
@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!

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Nov 11, 2026
@abhishekverma-ray

Copy link
Copy Markdown
Contributor

Thanks for these! The team is aligning on some Ray Data test conventions (#67919 / #67928). In short: each test should fail if the change is reverted, extend or parametrize existing tests before adding new ones, test through the public read_* APIs rather than asserting on internal mock calls, and use ray_start_regular_shared instead of starting new clusters. This PR has about 2.4× more test lines than code. Could you trim it to the tests that catch a revert, and note in the description which revert each one catches?

richardliaw pushed a commit that referenced this pull request Nov 17, 2026
## Description

Fix DataSourceV2 filters on synthesized columns such as `path`,
preventing incorrect partition pruning and Arrow field-binding errors.

**Before:** A `path` predicate could use a same-named Hive partition
value or reach the physical Arrow scan.

**After:** Enabled synthesized columns are excluded from
partition-column classification. Arrow-backed scanners push safe
physical predicates and retain synthesized or mixed predicates as
residual filters. MCAP uses the same partition classification. Existing
scanner fields and constructor signatures are preserved.

**Subsystems:** IO; logical planning / query optimization (regression
coverage).

```mermaid
flowchart LR
    subgraph Before["Before — IO: Arrow-backed scanner"]
        B1["path predicate"] --> B2["Partition pruning or Arrow scan"]
        B2 -->|Incorrect pruning or binding| B3["Incorrect result or error"]
    end
    subgraph After["After — IO: Arrow-backed scanner"]
        A1["Classify predicate"] -->|Physical predicate| A2["Arrow scan"]
        A1 -.->|Synthesized or mixed predicate| A4["Residual Filter"]
        A2 --> A3["Reader adds synthesized columns"]
        A3 -->|Residual present| A4
        A3 -->|No residual| A5["Output"]
        A4 --> A5
    end
    classDef changed fill:#fff9c4,stroke:#f9a825,color:#000
    classDef error fill:#ffcdd2,stroke:#c62828,color:#000
    class B2,A1,A4 changed
    class B3 error
```

## Related issues

Fixes #66916. Related to #66572.

#66572 is open and proposes configurable Parquet path-column names and
same-named file-column projection fixes; this PR addresses
synthesized-column predicate classification and filtering.

## Additional information

**Testing:** These selections passed on Linux ARM64 with Python 3.12 and
PyArrow 23.0.1, using Ray `a9843db` native binaries and source with this
PR’s Python changes applied. Environment and reporting options are
omitted.

```bash
python -m pytest -q python/ray/data/tests/unit/datasource_v2/test_arrow_file_scanner.py::test_push_filters_retains_synthesized_residual python/ray/data/tests/unit/datasource_v2/test_file_scanner.py::test_partition_columns_exclude_enabled_synthesized_columns  # 18 passed
python -m pytest -q python/ray/data/tests/test_predicate_pushdown.py::test_synthesized_path_filters_use_output_values python/ray/data/tests/test_predicate_pushdown.py::test_synthesized_path_residual_preserves_read_constraints  # 5 passed
python -m pytest -q python/ray/data/tests/datasource/test_orc.py::test_read_orc_v2_filter_path_from_directory  # 1 passed
python -m pytest -q 'python/ray/data/tests/datasource/test_mcap.py::test_read_mcap_v2_filter_path_over_same_named_partition[v2]'  # 1 passed
```

**Revert checks:** The FileScanner, MCAP, and Hive Parquet cases catch
the partition-classification revert. The Arrow Scanner, ORC directory,
unpartitioned Parquet, and residual-plan cases catch the Arrow-pushdown
revert; ORC inherits that implementation during this check. Every
selected case also fails when all three production changes are reverted.

Synthesized-column residual filters run after reading and can reduce
pruning and early-limit opportunities. Broader same-named
physical-column projection behavior is outside this fix.

Codex AI assistance was used for implementation, validation, and review.

---------

Signed-off-by: jiangxt2 <[email protected]>
@jiangxt2
jiangxt2 requested a review from a team as a code owner November 18, 2026 03:40

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 unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants