Repository navigation
[Data] Align partition pruning with logical schema types - #67073
richardliaw merged 7 commits into
Conversation
Evaluate Parquet and ORC path predicates with the full logical schema and the reader's Arrow conversion helper, casting only referenced fields. Preserve ORC missing-key deferral, keep post-UDF filters above the read, and decouple read-side pruning from the optional listing pruner. Signed-off-by: jiangxt2 <[email protected]>
Signed-off-by: jiangxt2 <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces typed partition pruning for datasource V2, ensuring that partition values parsed from file paths are cast to the reader's logical schema types before evaluating predicates. It refactors partition value broadcasting into a shared helper, disables predicate pushdown when post-read UDFs are present, and adds extensive tests for Parquet and ORC formats. The review feedback highlights a critical runtime NameError in orc_file_reader.py due to a missing import of get_column_references and a missing null guard, as well as an optimization opportunity in partitioning.py to return early when no partition columns are referenced by the predicate.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 078a3d0. Configure here.
|
Thanks — the fix is right and the tests are excellent (31 of them, and the post-UDF test Before merging I'd like to sort out #67067, which is open from the same base. It adds |
Allow filters on columns untouched by tensor decoding to push down while preserving the barrier for transformed columns and arbitrary block UDFs. Include partition paths in ArrowInvalid errors. Signed-off-by: jiangxt2 <[email protected]>
Thanks for the review. I agree the two PRs overlap, but I’d keep #67073 as the primary PR to land first because its scope is more focused. #67067 is not ready yet and may need further changes. After #67073 merges, I’ll rebase #67067 and handle any conflicts. |
Narrow logical operators and annotate tensor schema test data so the Data Pyrefly check can validate the new regression tests. Signed-off-by: jiangxt2 <[email protected]>
Run the CI-pinned type checker on changed Data files while respecting the existing CI exclusion list. Narrow the FileReader schema locally for the changed-file check. Signed-off-by: jiangxt2 <[email protected]>
Signed-off-by: jiangxt2 <[email protected]>
Remove the Data Pyrefly pre-commit hook, its helper, and the ancillary schema narrowing. Merge origin/master while retaining both sides of the Parquet tests. Signed-off-by: jiangxt2 <[email protected]>
Merge master and reuse the partition conversion helper and scanner factory from ray-project#67073. Preserve conservative mixed-root filtering and footer limit proofs, add file paths to conversion errors, and cover the integration with targeted regressions. Signed-off-by: jiangxt2 <[email protected]>
…#67073) ## Description Ray Data's DataSourceV2 path pruning can compare a string parsed from a partition path with the same field's numeric Arrow type, causing a valid predicate such as `year == 2024` to fail. This change passes the full scanner schema to partition pruning and reuses the reader's Arrow conversion helper. It aligns Parquet and ORC filtering for projected reads and Parquet prelisted inputs. Only predicate-referenced fields are cast; read-side pruning is independent of the listing hook; filters remain after opaque block UDFs; ORC missing-key handling remains deferred to the reader. ## Related issues Fixes ray-project#66915. ray-project#67067 covers mixed-root filtering for ray-project#66914; this PR covers logical-type partition evaluation and UDF/listing pruning boundaries. Synthesized-path filtering tracked by ray-project#66916 remains separate. ## Additional information ### Validation The implementation was validated on Linux/aarch64 with Python 3.12.14, PyArrow 23.0.1, pandas 2.3.3, and NumPy 2.2.6. The Ray runtime matched the source baseline, and driver/worker source identities were checked. - `python -m pytest -q` on six logical-read, scanner, listing-pushdown, and ORC unit-test modules: **436 passed**. - `python -m pytest -q python/ray/data/tests/datasource/test_read_parquet_v2.py`: **91 passed**. - `python -m pytest -q` on selected ORC V2 partition regressions in `test_orc.py`: **118 passed**. - Parser/callback and Parquet compatibility selections: **178 previously passing cases reused** after per-case review; not rerun. - `python -m pytest -q` on the two new ORC cases and both parameters of `test_prelisted_partition_filter_uses_logical_types` in `test_read_parquet_v2.py`: **4 passed, 0 failed, 0 errors, 0 skipped**. The tests ran on a local single-node Ray cluster using the PR Python-source overlay. Ray 2.59.0 does not support `local_mode=True`; its native wheel and the PR Python sources were from different revisions, producing a non-fatal CoreWorker compatibility warning. After pytest completed, Ray's log-subscriber thread reported `InvalidAuthToken`; the JUnit report records all four tests as passed. The latest pre-commit and local static checks passed. ### AI assistance Codex AI assistance was used for implementation, tests, and review. --------- Signed-off-by: jiangxt2 <[email protected]>
Resolve conflicts with ray-project#67073 in partitioning.py and test_partitioning.py. Signed-off-by: hzmsh <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
## Description Fix order-dependent filtering of mixed root/Hive-partitioned files in Parquet and ORC V2. **Before:** first-path discovery and path-only pruning can lose root matches. **After:** discover fields within the existing sample, retain unknown paths, and filter using per-file path, physical, or logical-null values. - Reuse prepared partition parsers across paths and fragments, alongside #67073's shared conversion helper, pruner and scanner factory. Known path predicates use Native evaluation, preserving string concatenation and boolean/null semantics; conversion errors retain their path, type and cause. - Keep the complete reader predicate and projection dependencies. Parquet footer rows count toward listing Limit only when the complete predicate is proven for the whole group, in ordinary and prelisted reads. - Centralize typed partition-value synthesis in `FileReader`, with a per-file value lookup hook. Parquet and ORC use per-fragment scan schemas and synthesize before residual filtering. ## Related issues Fixes #66914. #67073 supplies logical-type alignment; this PR repairs mixed-root layout handling. The duplicate-work check found no other open PR for #66914. ## Additional information Subsystems: IO, with logical planning / query optimization regression coverage. ```mermaid flowchart LR subgraph IO["IO / DataSourceV2"] P[Shared typed path pruning] --> R[Per-file row filtering] P --> F[Parquet footer full-match proof] F --> L[Safe listing Limit] end ``` ### Validation Linux arm64, Python 3.12, PyArrow 23.0.1: 114 targeted cases pass, none skipped (63 unit; 51 Parquet/ORC API). Coverage includes parser reuse across concurrent reads, sample order, casts/unused fields, Native string predicates, projection/count/Limit, safe early stop, fallback, tensor output, optional listing hooks, shuffle and read-unit exclusion. These selections reproduce that coverage in a Ray source development environment: ```bash export RAY_DATA_PARQUET_READER_IO_THREAD_COUNT=4 RAY_DATA_PARQUET_READER_CPU_COUNT=2 RAY_DATA_PARQUET_FOOTER_NUM_ACTORS=2 RAY_DATA_PARQUET_FOOTER_IO_CONCURRENCY=4 python -m pytest -q \ python/ray/data/tests/unit/datasource_v2/test_file_indexer.py \ python/ray/data/tests/unit/datasource_v2/test_parquet_datasource_v2.py \ python/ray/data/tests/unit/datasource_v2/test_orc_datasource_v2.py \ -k 'schema_aware_partition_pruner or test_partition_pruner or path_predicate or partition_discovery or partition_parsers_reuse or read_pruning or reader_partition_conversion or partition_path_outside or mixed_root_reader or footer_listing_stops or tensor_reader_preserves or resolve_partitioning_and_reuse or test_missing_partition_column_without_projection' python -m pytest -q \ python/ray/data/tests/datasource_v2/test_footer_reader.py \ -k 'partition_parser_is_reused or partition_filter_root_survivor_counts or path_value_overrides_physical_statistics or partition_filter_keeps_physical_statistics_pruning or unsampled_partition_column or root_physical_condition_can_still_prove or root_statistics_with_different_logical_type or footer_partition_conversion_error or declared_schema_cast_prevents' python -m pytest -q \ python/ray/data/tests/unit/datasource_v2/test_read_units.py python -m pytest -q \ python/ray/data/tests/unit/datasource_v2/test_synthesized_columns.py python -m pytest -q \ python/ray/data/tests/datasource/test_read_parquet_v2.py::test_partition_string_concatenation_matches_native_filter python -m pytest -q \ python/ray/data/tests/datasource/test_read_parquet_v2.py \ -k 'mixed_root or root_physical_partition_filter or partition_filter_ignores_unprojected or partition_conversion_error_includes_file_path or typed_partition_filter_preserves' python -m pytest -q \ python/ray/data/tests/datasource/test_orc.py \ -k 'conversion_error_includes_file_path or does_not_cast_unused or mixed_root_partition_filter_order or float32_logical_type or typed_partition_prunes_before_worker' ``` Automatic discovery uses the schema sample (16 files by default); explicit partition fields bypass discovery, and `merge_schema=True` examines all eligible files. A key absent from both sampled paths and physical schemas can remain absent from the planned schema. Black, Ruff/import sorting, pydoclint and cumulative Pyrefly checks pass. Validation is limited to these selections and this runtime baseline. Pre-existing tensor-plus-mixed-root projection and ORC explicit-`field_types` root-file parsing limitations remain outside this PR. AI assistance was used for implementation, tests and review. --------- Signed-off-by: jiangxt2 <[email protected]>

Description
Ray Data's DataSourceV2 path pruning can compare a string parsed from a partition path with the same field's numeric Arrow type, causing a valid predicate such as
year == 2024to fail.This change passes the full scanner schema to partition pruning and reuses the reader's Arrow conversion helper. It aligns Parquet and ORC filtering for projected reads and Parquet prelisted inputs. Only predicate-referenced fields are cast; read-side pruning is independent of the listing hook; filters remain after opaque block UDFs; ORC missing-key handling remains deferred to the reader.
Related issues
Fixes #66915. #67067 covers mixed-root filtering for #66914; this PR covers logical-type partition evaluation and UDF/listing pruning boundaries. Synthesized-path filtering tracked by #66916 remains separate.
Additional information
Validation
The implementation was validated on Linux/aarch64 with Python 3.12.14, PyArrow 23.0.1, pandas 2.3.3, and NumPy 2.2.6. The Ray runtime matched the source baseline, and driver/worker source identities were checked.
python -m pytest -qon six logical-read, scanner, listing-pushdown, and ORC unit-test modules: 436 passed.python -m pytest -q python/ray/data/tests/datasource/test_read_parquet_v2.py: 91 passed.python -m pytest -qon selected ORC V2 partition regressions intest_orc.py: 118 passed.Parser/callback and Parquet compatibility selections: 178 previously passing cases reused after per-case review; not rerun.
python -m pytest -qon the two new ORC cases and both parameters oftest_prelisted_partition_filter_uses_logical_typesintest_read_parquet_v2.py: 4 passed, 0 failed, 0 errors, 0 skipped.The tests ran on a local single-node Ray cluster using the PR Python-source overlay. Ray 2.59.0 does not support
local_mode=True; its native wheel and the PR Python sources were from different revisions, producing a non-fatal CoreWorker compatibility warning. After pytest completed, Ray's log-subscriber thread reportedInvalidAuthToken; the JUnit report records all four tests as passed.The latest pre-commit and local static checks passed.
AI assistance
Codex AI assistance was used for implementation, tests, and review.