kamcheungting-db opened a new pull request, #1167:
URL: https://github.com/apache/iceberg-cpp/pull/1167

   ## What this PR does
   
   Adds `ParallelScanReader` (`iceberg/data/parallel_scan_reader.h`), which 
reads the groups of a `FileScanTaskGroupStream` (from #1113) with a fixed set 
of workers and returns one Arrow C stream.
   
   ```cpp
   auto groups = scan->PlanTasksStream();
   auto stream = ParallelScanReader::Open(
       std::move(*groups), {.reader_options = reader_options,
                            .worker_count = 8,
                            .max_queued_batches = 16,
                            .max_queued_bytes = 64 << 20});
   ```
   
   ## How it works
   
   ```
    group stream ──(one worker at a time, outside locks)──> worker 1..N
                                                             │ own 
FileScanTaskReader
                                                             │ tasks of a group 
in order
                                                             v
                                          size batch ── admit in FIFO order ──> 
output queue ──> get_next
   ```
   
   - **Planning.** Workers claim groups through a planning token: only one 
calls the single-pass group stream at a time, and never under a lock. The 
stream is destroyed as soon as it is exhausted, so planning metrics are 
reported at EOF.
   - **Reading.** Each worker owns a `FileScanTaskReader`. Residual filters are 
always enforced (`apply_residuals` is forced on). Each task stream's schema is 
compared with the projected schema before its batches are read.
   - **Queue.** Batches enter a queue bounded by count (`max_queued_batches`) 
and by charged bytes (`max_queued_bytes`). Producers are admitted in FIFO 
order. A batch larger than the byte budget enters only an empty queue, as its 
sole batch. Zero-byte batches still count toward the batch limit. A worker 
holds at most one completed batch while it waits.
   - **Charging.** `ArrowBatchSizer` charges a batch as the checked sum of the 
spans of all present buffers, including children, dictionaries, and variadic 
buffers. Before nanoarrow sizes anything, it checks offsets, lengths, buffer, 
child, and dictionary counts, and every layout-dependent size product for 
overflow. List views and run-end encoded arrays are rejected.
   - **Errors and release.** The first planning, read, schema, or sizing error 
stops new work, releases queued batches, and is returned from the next 
`get_next` as `EIO`, with the file and byte range in `get_last_error()`. 
Releasing the stream between callbacks stops the workers, releases batches that 
were not returned, and joins the threads; batches already returned stay valid. 
No callback, release, or join runs under a lock.
   
   `iceberg_data` now links `Threads::Threads` unconditionally, including with 
`ICEBERG_SPDLOG=OFF`.
   
   The queue limits bound admission, not process memory: format reader buffers, 
delete indexes, and arrays already returned to the caller are outside the 
budget. The header documents this, the per-worker memory estimate, and the 
preconditions (registered format factories, a `FileIO` that supports concurrent 
reads, immutable task metadata, a planning executor that outlives the stream, 
and matching `case_sensitive`).
   
   ## Tests
   
   New `parallel_scan_test`, which links only `iceberg_data` and builds with 
`ICEBERG_BUILD_BUNDLE=OFF`. It uses hand-built groups and a scoped fake reader 
registered for Parquet and Avro:
   
   - zero, one, and many groups; 1 versus N workers return the same rows; mixed 
formats in a group; residuals enforced
   - task-local order across interleaved groups
   - schema mismatch, open failure, read failure (with the file range in the 
message), reader exceptions, and planning failures and exceptions; errors are 
sticky
   - bytes binding before count, count binding before bytes, zero-byte batches, 
oversized singletons, and an oversized batch not starved by small ones
   - releasing between callbacks while producers wait, releasing without 
reading, and callers keeping a returned array after release; every fake array 
is released exactly once
   - the group stream is destroyed at the end of planning, and its destructor 
can query metrics
   - `ArrowBatchSizer`: fixed width, sliced, variable width, nested, 
dictionary, string view, zero-column structs, unsupported list views, and 
overflow and malformed-count rejections
   
   The suite passes repeatedly under ThreadSanitizer and AddressSanitizer with 
UndefinedBehaviorSanitizer, with the bundle and spdlog off. Real Parquet and 
Avro tables are covered in Part-5. `pre-commit` is clean.
   
   ## Related
   
   Part 1 #976 · Part 2a #1002 · Part 2b #1062 · Part 2c #1065 · Part 3 #1113. 
Part 5 adds end-to-end validation and a benchmark. #1166 makes residual 
evaluation scale across workers.
   
   This pull request and its description were written by Isaac.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to