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

   ## What does this PR do?
   
   Adds consumer ID integration into `AsyncStreamingTableScan` and 
`StreamReadBuilder`, enabling streaming read progress to be persisted to and 
restored from Paimon's consumer files on restart.
   
   ## Changes
   
   **`StreamReadBuilder`**
   - New `.with_consumer_id("my-id")` builder method — passes a consumer ID 
through to `AsyncStreamingTableScan`
   
   **`AsyncStreamingTableScan`**
   - New `consumer_id` constructor parameter; creates a `ConsumerManager` when 
set
   - On `stream()` entry: if `next_snapshot_id` is `None`, restores position 
from the consumer file (allowing resume after restart)
   - Consumer position is persisted using a **stage/flush** pattern for 
at-least-once semantics:
     - `_stage_consumer()` records `next_snapshot_id` before each `yield` (no 
I/O)
     - `_flush_pending_consumer()` writes to storage at the generator resume 
point — i.e. when the caller calls `__anext__()` after finishing processing the 
previous plan
     - This ensures the consumer file only advances *after* the caller has 
processed the plan, matching the semantics of the Java connector's 
`notifyCheckpointComplete`
   
   ## Usage
   
   ```python
   scan = (
       table.new_stream_read_builder()
       .with_consumer_id("my-pipeline")
       .with_poll_interval_ms(500)
       .new_streaming_scan()
   )
   reader = table.new_stream_read_builder().new_read()
   
   async for plan in scan.stream():
       arrow_table = reader.to_arrow(plan.splits())
       write_to_sink(arrow_table)
       # consumer position is flushed automatically on the next iteration
   ```
   
   On restart, `scan.stream()` will restore from the saved consumer position 
and resume from where it left off.
   
   ## Part of streaming read PR stack
   
   Builds on #7424 (merged). Tracking issue: #7152
   
   | PR | Branch | Status |
   |---|---|---|
   | #7424 | `python-streaming-2c-scan-and-builder` | Merged |
   | this PR | `python-streaming-2d-consumer` | Draft |
   | — | `python-streaming-2e-acceptance-docs` | Not yet open |
   
   ## Test plan
   
   ```bash
   python -m pytest pypaimon/tests/streaming_table_scan_test.py 
pypaimon/tests/stream_read_builder_test.py -v
   ```
   
   New tests cover: consumer restore on startup, consumer save timing (staged 
before yield, flushed on next `__anext__()`), no consumer when `consumer_id` 
not set, consumer ID wired through `StreamReadBuilder`.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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