TheR1sing3un opened a new pull request, #7740:
URL: https://github.com/apache/paimon/pull/7740

   ## Purpose
   
   Today, reading a Paimon table into a Ray Dataset requires the caller to 
first build a TableRead by hand:
   
   ```python
   catalog = CatalogFactory.create({"warehouse": ...})
   table = catalog.get_table("db.table")
   rb = table.new_read_builder()
   read = rb.new_read()
   splits = rb.new_scan().plan().splits()
   ds = read.to_ray(splits)
   ```
   
   That works for the existing `TableRead.to_ray()` helper, but it forces every 
user to repeat the same catalog → table → builder boilerplate. The Iceberg 
integration has long had a single-line `IcebergDatasource(table_identifier, 
catalog_options, ...)`, and that's the missing surface here.
   
   This PR makes `RayDatasource` self-contained and adds a top-level facade so 
reading and writing a Paimon table from Ray is one call.
   
   ## Datasource refactor
   
   * `RayDatasource(table_identifier, catalog_options, predicate=None, 
projection=None, limit=None)` is the new constructor. The catalog, table, 
splits and `read_type` are loaded lazily via `@property` (`table`, `splits`, 
`read_type`), so the object is cheap to instantiate and easy to ship across Ray 
workers.
   * The legacy entry point — `TableRead.to_ray()` — keeps working through a 
new `RayDatasource._from_table_read(table_read, splits)` classmethod that wraps 
an already-resolved `(table_read, splits)` pair without a second catalog 
round-trip.
   * The read closure is hoisted to a module-level `_paimon_read_task` 
generator that yields one Arrow table per batch. This:
     * avoids the closure-over-`self` serialization overhead documented in 
[ray-project/ray#49107](https://github.com/ray-project/ray/issues/49107);
     * keeps memory proportional to one batch rather than the whole split chunk.
   
   ## New module: `pypaimon.ray`
   
   ```python
   from pypaimon.ray import read_paimon, write_paimon
   
   ds = read_paimon("db.table", catalog_options={"warehouse": "/path"})
   write_paimon(ds, "db.table", catalog_options={"warehouse": "/path"})
   ```
   
   `read_paimon(table_identifier, catalog_options, *, filter=None, 
projection=None, limit=None, ray_remote_args=None, concurrency=None, 
override_num_blocks=None, **read_args) -> ray.data.Dataset`
   
   `write_paimon(dataset, table_identifier, catalog_options, *, 
overwrite=False, concurrency=None, ray_remote_args=None) -> None`
   
   This PR introduces the basic shape only — follow-up PRs will layer on 
committer/message metadata (PR-3.2), `snapshot_id`/`tag_name` time travel 
(PR-3.3), small-file controls (PR-3.4), dynamic options (PR-3.5), and 
per-worker commit mode + retries (PR-3.6 / 3.7). Each kwargs slot is named so 
those follow-ups stay backward-compatible additions.
   
   ## Linked issue
   
   N/A — surfaced when wiring pypaimon into a Ray-based ingestion pipeline 
alongside Iceberg, where users expected a `read_paimon`/`write_paimon` facade 
analogous to `read_iceberg`/`write_iceberg`.
   
   ## Tests
   
   New `pypaimon/tests/ray_integration_test.py` (8 cases):
   
   * `test_read_paimon_basic` — round-trip of three rows.
   * `test_read_paimon_with_projection` — projection narrowing.
   * `test_read_paimon_with_filter` — predicate pushdown via `PredicateBuilder`.
   * `test_read_paimon_empty_table` — empty datasets work.
   * `test_write_paimon_basic` — write-then-read round-trip via the facade.
   * `test_write_paimon_overwrite` — `overwrite=True` replaces data.
   * `test_read_paimon_primary_key` — PK upsert + merge-on-read row count and 
values.
   * `test_read_paimon_invalid_override_num_blocks` — guards 
`override_num_blocks < 1`.
   
   Existing `ray_data_test` / `ray_sink_test` (which exercise 
`TableRead.to_ray()` and `PaimonDatasink` directly) continue to pass via the 
`_from_table_read` bridge — no behavioural change for those paths.
   
   Local: `pytest 
pypaimon/tests/{ray_data_test,ray_sink_test,ray_integration_test}.py` → 26 
passed; `flake8 --config=dev/cfg.ini` clean.
   
   ## API and format
   
   Public Python API additions (`pypaimon.ray.read_paimon`, 
`pypaimon.ray.write_paimon`). The existing `RayDatasource` constructor 
signature changes shape (now takes `table_identifier + catalog_options` instead 
of `table_read + splits`). The only in-tree caller of the old form, 
`TableRead.to_ray()`, is migrated to `RayDatasource._from_table_read()` in the 
same change. No external project should be importing `RayDatasource` directly 
today, but the bridge classmethod is kept available for callers that do.
   
   No file format change.
   
   ## Documentation
   
   Public docstrings on `RayDatasource`, `read_paimon`, and `write_paimon` 
describe the new contract and parameters.
   
   ## Generative AI disclosure
   
   Drafted with assistance from an AI coding tool; the design follows Iceberg's 
`IcebergDatasource` pattern, and every behavioural guarantee made by the new 
facade is exercised by a test in `ray_integration_test.py`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to