Repository navigation
[Data] Add partition_filters to read_delta and take file sizes from the log - #67900
richardliaw merged 2 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request enhances read_delta by adding support for partition_filters and optimizing file size lookups by retrieving them directly from the Delta log instead of making individual storage requests. It also adds a check to reject unsupported column-mapped Delta tables and includes comprehensive unit tests. The review feedback suggests defensive improvements to handle potential None values: specifically, ensuring delta.columnMapping.mode is safely handled before calling .lower() to avoid an AttributeError, and verifying that paths are not None before unquoting them in _delta_file_sizes to prevent a TypeError.
| column_mapping_mode = dt.metadata().configuration.get( | ||
| "delta.columnMapping.mode", "none" | ||
| ) | ||
| if column_mapping_mode.lower() != "none": |
There was a problem hiding this comment.
If the delta.columnMapping.mode key is present in the configuration but has a None or null value in the Delta log, dt.metadata().configuration.get("delta.columnMapping.mode", "none") will return None. Calling .lower() on it will then raise an AttributeError. We should defensively handle this by defaulting to "none" if the retrieved value is falsy or None.
| column_mapping_mode = dt.metadata().configuration.get( | |
| "delta.columnMapping.mode", "none" | |
| ) | |
| if column_mapping_mode.lower() != "none": | |
| column_mapping_mode = dt.metadata().configuration.get( | |
| "delta.columnMapping.mode", "none" | |
| ) or "none" | |
| if column_mapping_mode.lower() != "none": |
There was a problem hiding this comment.
Already handled: this check landed in ray-project/ray#67895 · [Data] Raise an error for Delta… with the or "none" guard, and this PR is now rebased on master.
| return { | ||
| urllib.parse.unquote(path): size | ||
| for path, size in zip( | ||
| actions["path"].to_pylist(), actions["size_bytes"].to_pylist() | ||
| ) | ||
| if size is not None | ||
| } |
There was a problem hiding this comment.
If a Delta table log is malformed or contains an add action with a null/missing path (which can be represented as None in PyArrow's to_pylist()), calling urllib.parse.unquote(path) will raise a TypeError. Adding a defensive check path is not None ensures that we only attempt to unquote and store valid paths.
| return { | |
| urllib.parse.unquote(path): size | |
| for path, size in zip( | |
| actions["path"].to_pylist(), actions["size_bytes"].to_pylist() | |
| ) | |
| if size is not None | |
| } | |
| return { | |
| urllib.parse.unquote(path): size | |
| for path, size in zip( | |
| actions["path"].to_pylist(), actions["size_bytes"].to_pylist() | |
| ) | |
| if path is not None and size is not None | |
| } |
There was a problem hiding this comment.
Added in 3fa409b. Add actions with a null path are now skipped, like those with a null size.
|
Could |
3e47100 to
89e35f4
Compare
|
I ran a couple of additional checks on this PR:
No issues found in these scenarios, LGTM! |
…he log `read_delta` had no way to read only some partitions: it built a PyArrow dataset with a fragment for every file in the table, called `get_file_info` on each one (one request per file on object storage) to size the read tasks, and opened every file even when a `filter` on a partition column left most of them empty. On a table with 26,085 files, of which a one-date read needs 60, that's 26,085 requests before the read starts. - `read_delta(partition_filters=...)` takes deltalake's tuple filters (an AND list, or an OR of AND lists) and passes them to `DeltaTable.to_pyarrow_dataset`, so only the matching partitions' files become fragments. deltalake 1.6.6 takes them as `file_pruning_predicate`; older versions as `partitions`, which only supports an AND list, so an OR of groups raises a clear error there. Every column must be a partition column: deltalake would prune other columns only by file statistics, so the result would no longer be exact. `read_unity_catalog` passes it through `reader_kwargs`. - File sizes come from the log's add actions. Their paths are URL-encoded once more than the fragment paths, so they're decoded once. `ParquetDatasource.from_pyarrow_dataset` takes them as `known_file_sizes` and calls `get_file_info` only for paths missing from it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
89e35f4 to
63ee9e6
Compare
…izes A malformed log entry with a null path would make urllib.parse.unquote raise. Skip it like a null size; the reader then falls back to get_file_info for that file. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Abhishek Verma <[email protected]>
Thanks for testing the encoding cases and the timing; that’s reassuring for large tables. 20K files in about 14 ms is negligible next to the per-file get_file_info calls this replaces. |
Thanks Aarya, you’re right that the fragments carry partition values and PyArrow can prune with them. I’d still like to keep partition_filters here: filter doesn’t prune files today. I checked: read_delta(path).filter(expr=col("date") == "...") still opens every file. Making it prune would mean new logic in the shared Parquet reader. Happy to add filter-based pruning here as a follow-up if you think it’s worth it. What do you think? |
…mn mapping in read_delta (#67895) (#68213) ## Description Cherry-pick of #67895 (master commit 3094de2) onto `releases/2.60.1`. **Bottom of a 2-PR stack on `releases/2.60.1`:** this PR, then #68214 (the #67900 pick). Merging #68214 with `gh stack merge` lands both in order. `read_delta` reads through `DeltaTable.to_pyarrow_dataset()`, which doesn't apply a Delta table's column mapping. A table with `delta.columnMapping.mode` set to `name` or `id` stores its columns in the data files under physical names such as `col-<uuid>`. With deltalake 1.6.4 to 1.6.6, a reader 2 / writer 5 table passes deltalake's own protocol check, and every mapped column comes back as nulls. `ds.schema()` still shows the right names, so nothing downstream notices. #67895 makes `read_delta`, and `read_unity_catalog` through it, raise `NotImplementedError` for these tables before reading. The message names the mode and points to #64854. Tables without column mapping, including an explicit `mode = none`, read as before. ## Related issues Related to #67895. Reading column-mapped tables is tracked in #64854. ## Additional information ### Cherry-pick details `read_api.py` applied cleanly with `git cherry-pick -x`. `test_delta.py` conflicted only on context. On master, the new tests follow `test_delta_read_deletion_vectors_message_is_actionable`, which #66275 added and which isn't on this branch. I kept only what #67895 adds: `import json`, `_write_column_mapped_table`, `test_delta_read_rejects_column_mapping` and `test_delta_read_column_mapping_mode_none`. The added lines are identical to the master commit's, in the same 2 files, +109/-0. Not a duplicate: neither `releases/2.60.1` nor any open or merged PR against it contains #67895. No open PR on any branch picks it. ### Testing The four suites are `datasource/test_delta.py`, `test_catalog.py`, `datasource/test_write_delta.py` and `unit/datasource/`, under `python/ray/data/tests/`. The last three are the other suites #67895 was tested with on master. `test_catalog.py` skips the whole module without `databricks-sdk`, and this branch's Data CI locks don't include it, so CI skips the file here. I ran it with `databricks-sdk` 0.143.0, in its own pytest process as Bazel would. Sharing a process with the other suites makes 10 of its tests, the ones that start their own Ray cluster, error with "Maybe you called ray.init twice". That happens on `releases/2.60.1` too. | Command | Result | |---|---| | `pre-commit run` on the 2 changed files | Passed | | `pytest datasource/test_delta.py datasource/test_write_delta.py unit/datasource/`, deltalake 1.5.0 | 202 passed. On `releases/2.60.1` without this PR: 199 passed | | `pytest test_catalog.py`, deltalake 1.5.0, databricks-sdk 0.143.0 | 34 passed, the same as on `releases/2.60.1` without this PR | | `pytest datasource/test_delta.py`, deltalake 1.5.0 and 1.6.6 | 18 passed on each. Without this PR: 15 passed | | The 3 new tests (`-k column_mapping`) with `releases/2.60.1`'s `read_api.py`, deltalake 1.5.0 and 1.6.6 | On each, `test_delta_read_rejects_column_mapping[name]` and `[id]` fail and `test_delta_read_column_mapping_mode_none` passes | The environment was Python 3.12.12 with the Ray 2.60.0 release wheel, which was built from `releases/2.60.0` at b7f4259. This branch's `python/ray/data` and `python/ray/tests` were copied over it. The other packages were pinned to the CI lock: pyarrow 23.0.1, pandas 2.3.3, numpy 2.2.6, fsspec 2023.12.1, and deltalake 1.5.0, or 1.6.6 where noted. `databricks-sdk` 0.143.0 was added for `test_catalog.py`. Building Ray from source for `bazel test` wasn't practical on my machine. An earlier version of this description counted `test_catalog.py` among the suites run. My run had skipped it because `databricks-sdk` wasn't installed. AI assistance was used to prepare this cherry-pick. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Abhishek Verma <[email protected]> Signed-off-by: Sai Miduthuri <[email protected]> Co-authored-by: abhishekverma-ray <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…ake file sizes from the log (#67900) (#68214) ## Description Cherry-pick of #67900 (master commit 63ff72c) onto `releases/2.60.1`. **Top of a 2-PR stack on `releases/2.60.1`:** #68213 (the #67895 pick), then this PR. Merging this PR with `gh stack merge` lands both in order. #67900 makes two changes to `read_delta`: - **`partition_filters`.** This new keyword-only parameter takes deltalake's `(column, op, value)` tuples. A flat list is an AND, and a list of lists is an OR of ANDs. Only the matching partitions' files become fragments, so only they are listed and read. Every column must be a partition column. An OR of groups needs deltalake 1.6.6 and raises a clear error on older versions. `read_unity_catalog` passes it through `reader_kwargs`. The default, `None`, keeps the current behavior. - **File sizes from the Delta log.** `ParquetDatasource.from_pyarrow_dataset` takes them as `known_file_sizes` and calls `get_file_info` only for paths missing from it. Before, it made one `get_file_info` request per file. On the 26,085-file table in #67900, that was 26,085 requests before a read started. `read_delta` is the only caller of `from_pyarrow_dataset` on this branch. ## Related issues Related to #67900. ## Additional information ### Cherry-pick details The #67900 commit applied cleanly with `git cherry-pick -x` on top of the #67895 pick. It has the same 3 files, +303/-3, and the same `git patch-id --stable` as the master commit. It needs #68213 because its `read_api.py` hunk sits right after the column-mapping check that #67895 adds. A second commit adds `from unittest import mock` to `test_delta.py`. `test_read_unity_catalog_partition_filters`, which #67900 adds, uses `mock.patch.object`. On master the import comes from #66275, which isn't on this branch, so ruff reports `F405` and the test would fail with a `NameError`. The import sits where master has it. Not a duplicate: neither `releases/2.60.1` nor any open or merged PR against it contains #67900. No open PR on any branch picks it. ### Testing The four suites are `datasource/test_delta.py`, `test_catalog.py`, `datasource/test_write_delta.py` and `unit/datasource/`, under `python/ray/data/tests/`. They're the suites #67900 was tested with on master. `test_catalog.py` skips the whole module without `databricks-sdk`, and this branch's Data CI locks don't include it, so CI skips the file here. I ran it with `databricks-sdk` 0.143.0, in its own pytest process as Bazel would. Sharing a process with the other suites makes 10 of its tests, the ones that start their own Ray cluster, error with "Maybe you called ray.init twice". That happens on `releases/2.60.1` too. The new `read_unity_catalog` test is in `test_delta.py`, so it runs either way. | Command | Result | |---|---| | `pre-commit run` on the 3 changed files | Passed with the `mock` import. Without it, ruff fails with `F405` on `mock` | | `pytest datasource/test_delta.py datasource/test_write_delta.py unit/datasource/`, deltalake 1.5.0 | 214 passed. #68213 alone: 202 passed | | `pytest test_catalog.py`, deltalake 1.5.0, databricks-sdk 0.143.0 | 34 passed, the same as with #68213 alone and on `releases/2.60.1` | | `pytest datasource/test_delta.py`, deltalake 1.5.0 and 1.6.6 | 30 passed on each. #68213 alone: 18 passed. Master has 31 because it also has #66275's test | `test_delta_read_partition_filters_or_groups` covers both deltalake paths. It reads an OR of groups through `file_pruning_predicate` on 1.6.6, and checks the "needs deltalake 1.6.6 or later" error on 1.5.0. The environment was Python 3.12.12 with the Ray 2.60.0 release wheel, which was built from `releases/2.60.0` at b7f4259. This branch's `python/ray/data` and `python/ray/tests` were copied over it. The other packages were pinned to the CI lock: pyarrow 23.0.1, pandas 2.3.3, numpy 2.2.6, fsspec 2023.12.1, and deltalake 1.5.0, or 1.6.6 where noted. `databricks-sdk` 0.143.0 was added for `test_catalog.py`. Building Ray from source for `bazel test` wasn't practical on my machine. An earlier version of this description counted `test_catalog.py` among the suites run. My run had skipped it because `databricks-sdk` wasn't installed. AI assistance was used to prepare this cherry-pick. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Abhishek Verma <[email protected]> Signed-off-by: Sai Miduthuri <[email protected]> Co-authored-by: abhishekverma-ray <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
…floop-input * upstream/master: [Data][3/n] update progress bar on lineage reconstruction (ray-project#67366) [Data] Enable the Top-N rewrite by default and expose it on DataContext (ray-project#68329) [Data] Adaptively skip map-side partial aggregation for high-cardinality keys (ray-project#68118) [Core] Spawn specific servers without preexec_fn to fix intermittent startup crashes (ray-project#67947) [Serve] Stop the __wrapped__ walk at non-callables (ray-project#67117) [Data] Deflake test_read_parquet_v2 by cutting redundant Ray Data executions (ray-project#68318) [Data] Retry FooterReader actor deaths with Ray Core and yield footers in listing order (ray-project#67988) [Data] Fix order-dependent schema unification when a list<null> arm is present (ray-project#68259) [Serve] Make @serve.batch work when wrapped in another decorator (ray-project#68177) [serve] Deflake test_metrics_3 - record the batch queue length once a batch is taken (ray-project#68302) [serve] Drop completed requests from the multiplexed model ID index (ray-project#68085) [Data] Fix flaky test_hudi: read each table once instead of sorting in Ray Data, keep size small (ray-project#68162) [Data] Fix flaky test_context: start 2 Ray clusters instead of 5 and keep size small (ray-project#68161) [Data] Fix flaky test_kafka: use recent timestamps in test_read_kafka_datetime_partial_range (ray-project#68248) [Data] Iceberg DSv2 [2/5]: The listing-to-reading manifest for Iceberg (ray-project#67951) [Train] Report training errors when the post-mortem debugger raises a BaseException (ray-project#68317) [RLlib] Skip the PPOConfig docstring example that crashes the rllib doctest target (ray-project#68306) [Train] Support post-mortem debugging for training function errors (ray-project#68296) [train][1/n] Give each health probe its own timeout (ray-project#68191) [Data] Fix unifying a fixed-shape tensor array with a lower-ndim variable-shaped one (ray-project#67266) [Train] Add a guide to debugging failures and hangs (ray-project#68299) [Data] Persist BlockMetadata.num_rows and batch ray.get in _calculate_blocks_rows (ray-project#67662) [Data] Vectorize LeRobot delta segment preparation and validate index contiguity (ray-project#67845) [Data] Avoid full-DataFrame apply in _AbstractKBinsDiscretizer._transform_pandas (ray-project#67862) [doc] Refresh intersphinx inventory snapshots (ray-project#68303) [Data] Fix SimpleImputer on categorical columns in append mode and with existing category values (ray-project#67467) [Data] Replace O(N) list.pop(0) with deque.popleft() in PushBasedShuffleTaskScheduler (ray-project#67243) [Train] Reject an elastic ScalingConfig with max_workers=0 (ray-project#68218) [core][move semantics][3/n]Populate task args with is_move for movable refs (ray-project#66803) [core][sandbox] Remove the readonly option (ray-project#68088) [Data](1/n) Implement the line-chunk reader for CSV and JSONL on DataSource V2 (ray-project#67907) [Data] Set MIMALLOC_PURGE_DELAY=0 on random_shuffle to fix the pyarrow 25 OOM regression (ray-project#68151) [core] Quote each `uv run` argument in the uv runtime env hook (ray-project#68156) [core] Don't let gRPC cancel calls that wait over 30s in the server queue (ray-project#68210) [Data] Fix shuffle and join on native tensor columns with pyarrow 25+ (ray-project#68072) [serve][llm] Remove decode load progress (ray-project#68258) [ci] Bump sglang to 0.5.23 in release tests (ray-project#68250) [Core] Build the test auth token file locally so Windows tests can read it (ray-project#68262) [image] Bump EFA installer to 1.51.0 in CPU base-extra images (ray-project#67730) [serve] Observe the result of rank reassignment reconfigures (ray-project#67923) [Serve][Docs] Explain imperative vs declarative deploys and in-place updates from Python (ray-project#68243) [Data] (Fault tolerance) Ray Data lineage reconstruction docs (ray-project#68061) [RLlib] Add a multi-node footsies APPO memory release test (ray-project#67595) [Train] Remove local mode (ray-project#68239) [Data] Fix filtered Lance row-count metadata (ray-project#67228) [Serve][2/2] Propagate TracingConfig to proxies at startup (ray-project#65437) [Data] Fix synthesized path filtering in DataSourceV2 (ray-project#67079) [RLlib] Run the BCConfig Tune example one trial at a time to unblock the rllib doctest target (ray-project#68242) [Data][Delta DSv2][2/7] List Delta Lake table files from the log (ray-project#67888) [Data] Parallelize Parquet and ORC full-schema reads (ray-project#67542) [Data] Random Shuffle on Shuffle V2 Map/Reduce Operators (ray-project#68004) [Data] Propagate metadata prefetch thread failures to executor (ray-project#68171) [core] Send generator consumed-progress updates from io_service_ (ray-project#67160) [Data] Add @ray-data-connectors as codeowner for datasource/sinks files (ray-project#68154) [data][llm] Keep the prompt in vLLM error rows (ray-project#67665) [data][actor-only][3/n] Actor-only backend: operator fusion (ray-project#67699) [Data] Read text files on DataSource v2 (ray-project#68063) [Autoscaler][KubeRay] Never patch worker group replicas below minReplicas (ray-project#67332) [Serve] Show progress of updating (ray-project#67107) [core][test] Trigger usage-stats OOM test without exhausting host memory (ray-project#68009) [Serve] Remove unused RAY_SERVE_HAPROXY_INGRESS_RETRY_ON and RAY_SERV… (ray-project#68175) [Data] Implement lineage tracker garbage collection upon marking operator durable (ray-project#67788) [Core] Fix recovery suppression race in ObjectRecoveryManager (ray-project#64974) [serve] Pass grpc.so_reuseport to gRPC as an integer (ray-project#66816) [Autoscaler][v2] Preserve retry accounting when trimming status history (ray-project#67360) [doc] Refresh intersphinx inventory snapshots (ray-project#68069) [Doc] Add item to AGENTS.md to update documentation when modifying API-facing code. (ray-project#68204) [Train] Preserve `num_boost_round=0` and avoid mutating `callbacks` in legacy LightGBM/XGBoost trainers (ray-project#68145) [Train] Raise in prepare_data_loader instead of dropping a custom batch_sampler (ray-project#68201) [air] Return None in skip_exceptions when exc or StartTraceback cause is None (ray-project#68172) [Train] Fix `checkpoint_manager` to support metrics only reported in a validation function (ray-project#67909) [Train] Count elastic workers in resource units for fractional resources (ray-project#68139) [Data] Refactor Disk shuffle map to use map Operator (ray-project#67130) [core][move semantics][2/n] Change state to moved on consumption and add enforcements (ray-project#66767) [Data] Propagate labels to object-store SHUFFLE_V2 map/reduce tasks (ray-project#67135) feat(core): add Cambricon MLU resource support (ray-project#66368) [Data] Make `zero_copy_batch=False` copy default batches (ray-project#67154) [data] Fix Parquet filename suffix detection (ray-project#67156) [data] Fix docstring/behavior mismatches in read_json and Dataset.sort (ray-project#66927) [Data] Run video_object_detection.ray on T4s with more memory (ray-project#68149) [core][sandbox] Let a node override network="public" sandboxes' default resolvers (ray-project#67691) [Data] read_mcap: resolve each sample's steps and lay out its row (ray-project#67925) [Data] read_mcap: sample read inputs: TopicSpec, steps, match and samples checks (ray-project#67924) [Data] Keep a map task's buffered rows when max_errored_blocks skips its error; read past corrupt MCAP chunks (ray-project#67167) [core][move semantics][1/n] Adding consume_once flag in actor methods (ray-project#66620) [Data] Size the schema pin and the columns Ray adds in the Parquet decoded-size estimate [3/6] (ray-project#67838) [Serve][LLM][1/3] Token based autoscaling: track autoscaling workload in KV router (ray-project#67937) [Data] Add native direct reads for nonpartitioned Hive tables (ray-project#67114) [Train] Count elastic workers in resource units for fractional resources (ray-project#68139) [Data] Add `condition` to `Dataset.join` and extract equi-join keys from it (ray-project#67590) [data] Add Top-N execution (ray-project#66931) [build] Bazel 8.8.1: bump protobuf to v29.6, rules_java to 8.12.0 and gRPC to 1.69.0 (ray-project#66483) [build] Use Arena::Create and pin Java 8 bytecode ahead of protobuf 29 / rules_java 8 (ray-project#67720) [core][sandbox] Don't join a sandbox's cgroup on every exec (ray-project#67690) [Data] Run `training_ingest_regression_test` on Instances that can be Provisioned (ray-project#68110) [Data] Run Sort on Disk-based Shuffle under SHUFFLE_V2 (ray-project#67850) [core] Deflake tests that race on timing (ray-project#67717) [ci] Bump pypa manylinux2014 base image to 2026.10.22-0 for CPython 3.15 (ray-project#67285) [Data] Make Mcap Data Column Test Insensitive to Struct Field Order (ray-project#68109) [Data] read_mcap V2: cut large files where their log-time order holds (ray-project#67166) [core][sandbox] Commit sandbox as new registry image (ray-project#67972) [Data] read_mcap V2: read neighbouring chunks in one ranged request (ray-project#67930) [train][4/n] Wire WorkerProbes through the HealthManager (ray-project#67915) [train][3/n] Add WorkerProbe results and health reports to the HealthState (ray-project#67879) [Data] (Data fault tolerance ray-project#6/6) Add a manual release test for lineage reconstruction (ray-project#67519) [train][6/n] Act on health decisions in the Ray Train controller (ray-project#67856) [Train] Do not start an elastic worker group with zero workers (ray-project#68101) [Train] Keep the last checkpoint after a metrics-only report in local mode (ray-project#68070) [Data][2/n] Migrate GPU Shuffle to Unified Phase Metrics (ray-project#67359) [Data][Chkpt] Fix `ArrowInvalid` when loading large generated-ID checkpoints (ray-project#68065) [core][test] Create auth token in test_redis_wrong_password (ray-project#68014) [data][actor-only][2/n] Actor-only backend: promote task pools to actor pools (ray-project#67698) [Data] Fix typing mismatches in Dataset public API (ray-project#62077) [Data] read_mcap V2: carry read tasks' summary records in the manifest (ray-project#67929) [Data] Distinguish generated ID collisions with synthesized columns (ray-project#67164) [Data] Fix incorrect scale-up in rate-based autoscaler for custom resources (ray-project#66647) [Data][Delta DSv2][1/7] Shared Parquet and partitioning fixes for the Delta reader (ray-project#67887) [Data] Eliminate redundant aggregation shuffle (ray-project#67198) [Data] Raise minimum supported pyarrow to 23.0.0 and test up to 26.0.1 (ray-project#68005) [Train] Use the default validation timeout when a report's ValidationTaskConfig has none (ray-project#68045) [doc][train] Use the global batch size in the TensorFlow Train examples (ray-project#68006) [TPU] Default multi-slice MASTER_ADDR to slice 0 host 0 in SlicePlacementGroup (ray-project#67878) [Data] Estimate a Parquet row group's decoded Arrow bytes from its footer [2/6] (ray-project#67837) [Data] Predicate pushdown through joins: split conjuncts, derive one-sided OR weakenings (ray-project#67122) [Data] Add partition_filters to read_delta and take file sizes from the log (ray-project#67900) [Data] Stop writing Unity Catalog vended credentials to the environment (ray-project#67899) [Data] Raise an error for Delta tables with column mapping in write_delta (ray-project#67898) [Core] Add initial foundational configurations and flags for fork server (ray-project#67356) [core][sandbox] Image layers caching (ray-project#67874) [Doc][Train] Add device stream batch prefetching section to accelerator guide (ray-project#67779) [Train] Use user-defined train function name in training thread name and error stack traces (ray-project#64292) [serve][docs] Remove beta label from custom autoscaling policies (ray-project#68046) [core] Don't treat a gRPC client with calls in flight as idle (ray-project#67718) [train] Fix checkpoint sorting to support nested metrics (ray-project#59130) [train][5/n] Run ControllerProbes on the controller's node monitor (ray-project#67671) [Train] Rank a checkpoint without the score attribute as worst in min order (ray-project#67901) [Core][RuntimeEnv] Stream runtime environment package downloads (ray-project#67184) [core] Deflake `_run_hanging_command` tests (ray-project#67461) [Data] Add Gravitino Iceberg REST catalog provider (ray-project#67007) [Data] Fix mixed-root partition filtering in Parquet and ORC V2 (ray-project#67067) [core] Keep absl logging at ERROR unless GRPC_VERBOSITY is set (ray-project#67719) [Data][1/n]Add Shuffle Metrics Unification Instrumentation (ray-project#66968) [ci][release] Stop publishing Python 3.10 wheels and images (ray-project#67722) [serve] Copy the ASGI lifespan state into each request scope (ray-project#67844) [Serve][LLM][4/5] Support scale-to-zero application routing (ray-project#67087) [core][sandbox] Let GPU sandboxes request NVIDIA profiling capabilities (ray-project#67974) [Serve][LLM] Exclude LLMRouter from dashboard QPS (ray-project#67873) [Data] Read the Parquet SizeStatistics PyArrow doesn't expose [1/6] (ray-project#67836) Add perf metrics for 2.60.0 (ray-project#67727) [Observability / Train] Add Grafana Annotation support with Ray Train usage (ray-project#66958) Signed-off-by: Eugene Paniot <[email protected]> # Conflicts: # python/ray/data/_internal/planner/plan_udf_map_op.py
…(opt-in) (#68283) ## Summary Routes `ray.data.read_delta` through the Delta Lake DataSourceV2 reader behind the private, temporary `DataContext._use_delta_datasource_v2` (off by default). Last part of the split of #67676. #68284, #68285, #68330, #68407 and #68408 build on it. #68286 deletes the switch, so `use_datasource_v2` alone decides, as it does for `read_parquet` and `read_orc`. Replaces #67890, which was opened from a fork; earlier review is there. This PR is part of a GitHub stack, so its diff shows only this layer. ## Before `read_delta` opens the whole table on the driver (`DeltaTable.to_pyarrow_dataset()`), builds the full file list there, and reads it through the V1 `ParquetDatasource`, one read task per file. ## After With the switch on (and `use_datasource_v2`, already the default), `read_delta` reads through `DeltaDatasourceV2` (#68282): - The table on the driver is used only for its log metadata (`without_files=True` on deltalake before 1.6; later versions ignore it). - The file list is built in a Ray task from the log at the pinned version (#67888). - Files are split into row-group read units, and DSv2 pushdown and resume apply. - Files are listed in path order, so one version lists its files in one order however its log is checkpointed. `deltalake`'s own order follows the row layout of the latest checkpoint, which the protocol leaves to the writer. - `filesystem=`, `storage_options`, `catalog=` and `include_paths` behave as before. Some reads keep using the V1 reader, with an info log saying why: - Tables that `delta_datasource_v2_unsupported_reason()` rejects. V1 then reads the table that was checked, at the same version. On deltalake 1.6+ it reuses that table rather than loading it again; before 1.6 it reopens it with its file list. - Reads that pass `partition_filters` (added in #67900). The V2 reader doesn't apply them yet and would read every partition, so these reads go to V1 without opening the table for the V2 check, with their own info log. #68330 applies them in V2. `filter(expr)` on partition columns already prunes in V2. Later layers change this before #68286 makes V2 the default: - #68407 opens the table only once, in a Ray task, instead of on the driver and again in the listing. That task also rejects a log that names data files by absolute path (as a shallow clone's does), so `read_delta` fails right away. V1 can't read such tables either. - #68408 replaces the V1 fallback with errors. ### Changes from V1 - An empty table's `schema()` is the schema in the log. V1 returns `None`. - `input_files()` is empty until the read runs, because the files are listed in Ray tasks (as for `read_parquet` on DataSourceV2). - Read tasks hold row-group runs packed by size, not one file each. A large file can be split across tasks, and small files share one. - The log is read in Ray tasks (the listing here; from #68407 also the table open), so worker nodes, not only the driver, need read access to the table's `_delta_log`. Credentials in `storage_options` travel with the tasks. #68286 says so in the `read_delta` docstring. - A data file whose size is missing from the log is still read (its footer read finds the size); only files of size 0 are skipped. - With `preserve_order=True`, rows come back in path order. V1 reads files in `deltalake`'s order (newest commit first for JSON commits), which can change for one version when a checkpoint lays out its rows in another order. - Unchanged: the version is pinned when `read_delta` is called. ```mermaid flowchart TD subgraph Before subgraph BS[Subsystem: IO] subgraph BC["Component: read_delta (read_api.py)"] B1["driver: DeltaTable(...).to_pyarrow_dataset()<br/>(full file list)"] --> B2["V1 ParquetDatasource.from_pyarrow_dataset"] B2 --> B3["Read: one task per file"] end end end subgraph After subgraph AS[Subsystem: IO] subgraph AC["Component: read_delta → DataSourceV2 formats/delta"] A0{"_use_delta_datasource_v2, table supported<br/>and no partition_filters?"} -->|no| A5["V1 path (unchanged)"] A0 -->|yes| A1["driver: DeltaTable (log metadata)<br/>pin version, schema, partition cols"] A1 --> A2["ListFiles task: DeltaFileIndexer<br/>add actions at pinned version, sorted by path, footer reads"] A2 --> A3["OnlineBinPacker: row-group read units"] A3 --> A4["ReadFiles: DeltaScanner / ParquetFileReader"] end end end classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A0 changed class A1,A2,A3,A4 added ``` ## Subsystems API (`read_api.read_delta`, the private `DataContext._use_delta_datasource_v2`) carries the change; IO for the listing order, the README and the tests. ## Not a duplicate Split out of #67676, which takes over #65142 (tobby168, credited as co-author). richardliaw asked for a restart on the current DSv2 layout. No other open PR reads Delta through DSv2. ## Testing Same env as #67887 (deltalake 1.5.0, pyarrow 23). Each module runs in its own pytest process, as CI runs one `py_test` per file: - `test_delta.py`: 54 passed. `test_delta_v2.py`: 35 passed. `tests/datasource_v2/test_delta_footer_listing.py`: 2 passed. - `test_delta.py` runs under both readers through conftest's `datasource_v2` fixture. Tests that take the V1 path with either reader run once: the `partition_filters` tests (until #68330), the multiple-paths check, `_delta_file_sizes` and `use_datasource_v2 = False`. An empty table's schema from the log is a separate V2-only test. - The no-`get_file_info` check (`test_delta_read_takes_file_sizes_from_the_log`) runs under both readers. Its handler records each call in a file, so calls made inside Ray tasks count too. - What `test_delta_v2.py` checks, V2 only (`datasource_v2` fixture, `ray_start_regular_shared`), through `read_delta` and `Dataset` methods. It tells the readers apart by the read operator's name in `ds.stats()`. - V2 returns the same rows and schema as V1 for partitioned tables (special-character, null, int and date partitions). - Filters on partition and data columns, `columns=`, `include_paths` and a table-rooted `filesystem=`. - Count after overwrite, version pinning at call time, row-group splitting, the read order, a seeded shuffle, and each V1 fallback. - `test_delta_footer_listing.py` builds the indexer as `read_delta` does and lists the table: the row groups a resumed job skips, and those a filter prunes. Footer reads run in Ray actors, so these live in `tests/datasource_v2/`, not `tests/unit/`. - Tests that fail without this layer's fixes: - `test_a_version_reads_its_files_in_one_order` reads a table, rewrites its checkpoint with the rows in reverse order (as the protocol allows), and reads the same version again, through the same Dataset and a new `read_delta`. Without the path sort, the order changes; so does the listing-order check in `test_indexer_and_scanner_survive_worker_serialization`. - `test_snapshot_repr_leaves_out_storage_options` fails when `storage_options` is in the snapshot's `repr`. - `test_partition_filters_fall_back_to_v1` fails without the fallback (the read goes to V2). - `test_skips_only_empty_files` fails with the old size check, which also dropped files of unknown size. - `test_falls_back_to_v1_with_pyarrow_scan_options` appends to the table right after the check, with deltalake reporting 1.5 and 1.6. It checks that V1 reads the checked version and, on 1.6, opens the table once. Both cases fail with the old code, which reopened the latest version. - `test_partition_values_come_from_the_log` reads tables whose paths don't give their partition values: random file prefixes, timestamp partitions with a time zone, and the string `__HIVE_DEFAULT_PARTITION__` next to nulls. It reads them through V2 and matches V1, with and without a filter on the partition column. - `test_delta_read_does_not_unpickle_a_tampered_data_file`: a data file swapped for one with a pickled-object column reads as plain bytes under both readers, and its pickle never runs. The test also writes the swapped file's size into the log, because V2 opens data files with the log's sizes, as Delta readers do. - `test_s3_reads_send_no_head_requests` reads a table on moto S3, through deltalake's filesystem and through a caller's `SubTreeFileSystem` over S3. Using moto's request recorder, it checks that no data file gets a HEAD request. - `tests/unit/datasource_v2/` and `tests/unit/datasource/`: 1521 passed, 225 skipped. `test_write_delta.py`: 105 passed. - Each guard was removed one at a time, and a test failed each time: path decoding, the log-based whole-file indexer, version pinning, projection pinning, the protocol fallback, shuffle, the indexer's own filesystem, schema pinning against tampered files, the path order and the `repr`. - pre-commit and pyrefly (CI file set, with deltalake 1.5 and pyarrow 23 resolved) pass. AI assistance was used (Claude Code); every line has been reviewed by the submitter. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Abhishek Verma <[email protected]> Co-authored-by: tobby168 <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
read_deltagainspartition_filters, which lists and reads only the matching partitions' files, and takes file sizes from the Delta log instead of oneget_file_infocall per file.Before
read_deltahad no way to read only some partitions:DeltaTable.to_pyarrow_dataset()was called without a filter, so the dataset had a fragment for every file in the table.ParquetDatasource.from_pyarrow_datasetcalledget_file_infoon every fragment to size the read tasks: one request per file on object storage, although the sizes are in the Delta log.filteron a partition column became a PyArrow row filter, so every file was still opened.On a table with 26,085 files, a one-date read needs 60 of them; building the dataset took 26,085
get_file_inforequests before the read started.After
read_delta(partition_filters=...)takes deltalake's tuple filters:(column, op, value)with=,!=,<,<=,>,>=,in,not in. A flat list is an AND, and a list of lists is an OR of ANDs. Only the matching partitions' files become fragments, so only they are sized and read.file_pruning_predicate(AND or OR of ANDs). Older versions take them aspartitions, which only supports an AND list (deltalake 1.5.0 and 1.6.3 fail on an OR withnot enough values to unpack), so an OR of groups raises a clear error asking for 1.6.6 there.Dataset.filterfor those.read_unity_catalogpasses it throughreader_kwargs.p=a%2520bvsp=a%20b), so they're decoded once.ParquetDatasource.from_pyarrow_datasettakes them asknown_file_sizesand callsget_file_infoonly for paths missing from it.flowchart TD subgraph Before subgraph BS[Subsystem: IO] subgraph BC["Component: read_delta → ParquetDatasource.from_pyarrow_dataset"] B1["DeltaTable.to_pyarrow_dataset()<br/>every file"] --> B2["get_file_info per fragment"] B2 --> B3["read tasks: every file"] end end end subgraph After subgraph AS[Subsystem: IO] subgraph AC["Component: read_delta → ParquetDatasource.from_pyarrow_dataset"] A0["partition_filters<br/>(validated: partition columns only)"] --> A1["to_pyarrow_dataset(file_pruning_predicate | partitions)<br/>matching files only"] A1 --> A2["sizes from the Delta log<br/>(get_file_info only for misses)"] A2 --> A3["read tasks: matching files"] end end end classDef added fill:#c8e6c9,stroke:#2e7d32,color:#000 classDef changed fill:#fff9c4,stroke:#f9a825,color:#000 class A0 added class A1,A2 changedSubsystems
API (
read_api.read_delta, newpartition_filtersparameter) carries the change; IO forParquetDatasource.from_pyarrow_dataset'sknown_file_sizes.Not a duplicate
#62959 ("Add DeltaDatasource with partition predicate pushdown") was closed by the stale bot in May 2026 without review. No open PR adds partition filters to
read_delta. The DataSourceV2 Delta reader in review (#67888–#67890) prunes partitions fromfilter(expr); it will send reads withpartition_filtersto this reader until it supports them natively.Testing
macOS / Python 3.12, env pinned to the CI lock (pyarrow 23.0.1, deltalake 1.5.0):
pytest python/ray/data/tests/datasource/test_delta.py: 31 passed on deltalake 1.5.0, and 31 passed with deltalake 1.6.6 on the path. On a table with two files per date partition,Dataset.input_files()lists only the matching partitions' files, and the rows match, for:=,in, a range, and an AND of two conditions;ValueError;read_unity_catalog(reader_kwargs={"partition_filters": ...}).infocalls and partition values with special characters (a b,x/y,100%), building the dataset makes 0get_file_infolookups. With the log sizes disabled, it makes 4 (one per file)._delta_file_sizesmatches the real file sizes, keyed by the fragment paths deltalake builds, special characters and null partitions included.test_catalog.py: 46 passed;test_write_delta.py: 101 passed;tests/unit/datasource/: 94 passed.AI assistance was used (Claude Code); every line has been reviewed by the submitter.
🤖 Generated with Claude Code