)]}'
{
  "commit": "60447e78c3bcb738efb85f09b734b9aaea0cd72c",
  "tree": "c82335e8311efec055f8a35b1fd7603553d5a070",
  "parents": [
    "11be7bd0c796f9ab544d922f6b565691d8e6f8de"
  ],
  "author": {
    "name": "kamcheungting-db",
    "email": "91572897+kamcheungting-db@users.noreply.github.com",
    "time": "Tue Dec 01 01:59:08 2026 -0800"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Tue Dec 01 17:59:08 2026 +0800"
  },
  "message": "feat(data): Support split and parallel scans - Part-4: bounded parallel Arrow reader (#1167)\n\n## What this PR does\n\nAdds `ParallelScanReader` (`iceberg/data/parallel_scan_reader.h`), which reads the groups of a `FileScanTaskGroupStream` (from #1113) with a fixed set of workers on a caller-provided executor and returns one Arrow C stream.\n\n```cpp\nauto groups \u003d scan-\u003ePlanTasksStream();\nauto stream \u003d ParallelScanReader::Open(\n    std::move(*groups), {.reader_options \u003d reader_options,\n                         .executor \u003d \u0026executor,\n                         .worker_count \u003d 8,\n                         .max_queued_batches \u003d 16,\n                         .max_queued_bytes \u003d 64 \u003c\u003c 20});\n```\n\n## How it works\n\n```\n                          ParallelScanReader::Open(groups, options)\n                                       │ validate options, build the projected Arrow schema,\n                                       │ make one FileScanTaskReader + ArrowBatchSizer per worker\n                                       v\n  ┌──────────────────────────────── workers 1..N ────────────────────────────────┐\n  │                                                                              │\n  │  ClaimGroup()                                                                │\n  │    yield if busy; otherwise call groups-\u003eNext() outside all locks            │\n  │    (one worker at a time)          │                                         │\n  │                                    ├─ group ──\u003e release token, read it       │\n  │                                    ├─ end   ──\u003e destroy group stream, done   │\n  │                                    └─ error ──\u003e Stop(error)                  │\n  │                                                                              │\n  │  for each task in the group, in order:                                       │\n  │    reader.Open(task) ──\u003e check task schema \u003d\u003d projected schema               │\n  │      for each batch:                                                         │\n  │        sizer.Measure(batch)   preflight overflow checks, then sum buffer     │\n  │                               spans (children, dictionaries, variadic)       │\n  │        TryEnqueue(worker)      admit the head ticket if it fits;             │\n  │                                otherwise keep the batch and yield            │\n  └───────────────────────────────────────┬──────────────────────────────────────┘\n                                          v\n                ┌──────────── output queue ─────────────┐\n                │ admit when:                           │\n                │   count \u003c max_queued_batches  AND     │\n                │   charge \u003c\u003d max_queued_bytes:         │\n                │     queued + charge \u003c\u003d budget         │\n                │   charge \u003e  max_queued_bytes:         │\n                │     queue is empty (sole batch)       │\n                └───────────────────┬───────────────────┘\n                                    v\n                    get_next ──\u003e pop front, subtract charge, wake producers\n                                 (caller owns the array from here)\n                    end of stream when all workers finished and the queue is empty\n\n  Stop(error)  (first error wins)        release() between callbacks\n    stop new work                           stop new work\n    release queued batches                  release queued batches\n    get_next returns EIO;                   wait for running callbacks and submissions\n    get_last_error() gives the message      destroy the group stream\n                                            returned arrays stay valid\n```\n\n- **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.\n- **Reading.** Each worker owns a `FileScanTaskReader`. Residual filters are always enforced (`apply_residuals` is forced on). The projected schema must contain every field referenced by the task residual. Each task stream\u0027s schema is compared with the projected schema before its batches are read.\n- **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 and yields its executor thread.\n- **Charging.** `ArrowBatchSizer` currently estimates a batch\u0027s charge 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.\n- **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`. For task read errors, `get_last_error()` includes the file path and, for splits, the byte range. Releasing the stream between callbacks stops the workers, releases batches that were not returned, and waits for running callbacks; batches already returned stay valid. Queued executor callbacks that run later see the stop flag and return.\n\n`iceberg_data` now links `Threads::Threads` unconditionally, including with `ICEBERG_SPDLOG\u003dOFF`.\n\nThe 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 read executor that outlives the stream and its accepted callbacks, a planning executor that outlives the stream, and matching `case_sensitive`).\n\n## Tests\n\nThe parallel reader and batch sizer tests are part of `scan_test` (`ICEBERG_BUILD_BUNDLE\u003dON`). The parallel reader unit tests use hand-built groups and a scoped fake reader registered for Parquet and Avro:\n\n- zero, one, and many groups; 1 versus N workers return the same rows; mixed formats in a group; residuals enforced\n- task-local order across interleaved groups\n- executor submission failures, planning handoff, and workers yielding under queue backpressure\n- schema mismatch, open failure, read failure (with the file range in the message), reader exceptions, and planning failures and exceptions; errors are sticky\n- bytes binding before count, count binding before bytes, zero-byte batches, oversized singletons, and mixed small and oversized batches\n- releasing between callbacks while producers wait, releasing without reading, and callers keeping a returned array after release; every fake array is released exactly once\n- the group stream is destroyed at the end of planning, and its destructor can query metrics\n- `ArrowBatchSizer`: fixed width, sliced, variable width, nested, dictionary, string view, zero-column structs, unsupported list views, and overflow and malformed-count rejections\n\nA planned historical scan also checks that a missing residual field is reported rather than silently dropping rows. The bundle-enabled `scan_test` passes locally. Real Parquet and Avro tables are covered in Part-5. `pre-commit` is clean.",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "5c76f7a5466d9a84f0de2a43cd34e16b514c2b6b",
      "old_mode": 33188,
      "old_path": "cmake_modules/IcebergThirdpartyToolchain.cmake",
      "new_id": "1578c59a1857e7125405df0a4db1b6a2effcf37e",
      "new_mode": 33188,
      "new_path": "cmake_modules/IcebergThirdpartyToolchain.cmake"
    },
    {
      "type": "modify",
      "old_id": "285d0d8ed3fabdd89cfc8eb7f0af0450569c8031",
      "old_mode": 33188,
      "old_path": "src/iceberg/CMakeLists.txt",
      "new_id": "71c7a4018606af8dc4dc76e969e14a0d1ccc5ed0",
      "new_mode": 33188,
      "new_path": "src/iceberg/CMakeLists.txt"
    },
    {
      "type": "modify",
      "old_id": "5f730f321016791deba14f0b4f607c558a003d5e",
      "old_mode": 33188,
      "old_path": "src/iceberg/cpp20_compatibility_internal.h",
      "new_id": "5c2115c21ca45345b77d7a959e44b817eea4af92",
      "new_mode": 33188,
      "new_path": "src/iceberg/cpp20_compatibility_internal.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "5827a85fc07bb75fc12246a9f7952ae60507788a",
      "new_mode": 33188,
      "new_path": "src/iceberg/data/arrow_batch_sizer.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9ec9eafa67030c203c47220737d4b2994354807b",
      "new_mode": 33188,
      "new_path": "src/iceberg/data/arrow_batch_sizer_internal.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "709f0e01cb01d720bb7cde595862f9e9c299bc70",
      "new_mode": 33188,
      "new_path": "src/iceberg/data/parallel_scan_reader.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "c7541a9b9afee10669bf532506b985793bfcec9e",
      "new_mode": 33188,
      "new_path": "src/iceberg/data/parallel_scan_reader.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "6d5945de2e991ce0c67fe0eab3d5530171e8fcd2",
      "new_mode": 33188,
      "new_path": "src/iceberg/data/parallel_scan_reader_internal.h"
    },
    {
      "type": "modify",
      "old_id": "ff2d32507781e37b977f23f550df4f83f9d43908",
      "old_mode": 33188,
      "old_path": "src/iceberg/name_mapping.cc",
      "new_id": "d681a5056ac8b736b92ad631aac46aa6fd572b98",
      "new_mode": 33188,
      "new_path": "src/iceberg/name_mapping.cc"
    },
    {
      "type": "modify",
      "old_id": "7fd140c0d7e7409bdd12521fce31d6dd3b220b6d",
      "old_mode": 33188,
      "old_path": "src/iceberg/name_mapping.h",
      "new_id": "56b44d99ddfb6a753391a70423fb4242558881ba",
      "new_mode": 33188,
      "new_path": "src/iceberg/name_mapping.h"
    },
    {
      "type": "modify",
      "old_id": "c5d9883a2577730460ed9dfac522d6fad4cbcb78",
      "old_mode": 33188,
      "old_path": "src/iceberg/test/CMakeLists.txt",
      "new_id": "c69ad54c7d1c882c40cf10d7b307fdc6558631cf",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/CMakeLists.txt"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "03b942256b7274664fdec2cd8c9450a69b66717f",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/allocation_failure.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "9b02d848b48f514b6875204ef6c685e8fb4604f0",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/allocation_failure.h"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "00b131bd85e28525dbbef592f7432070bb004324",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/arrow_batch_sizer_test.cc"
    },
    {
      "type": "modify",
      "old_id": "236c2d0e8844e560f63a7e52adf650dbb4b320b1",
      "old_mode": 33188,
      "old_path": "src/iceberg/test/executor.h",
      "new_id": "a5dca3324b43d1b42b88b1de63eee8111f898c33",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/executor.h"
    },
    {
      "type": "modify",
      "old_id": "70f71560ad614e2128306bd14bc50496af309a85",
      "old_mode": 33188,
      "old_path": "src/iceberg/test/name_mapping_test.cc",
      "new_id": "069484417e846f0f30471ae9463d75f2a67007ec",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/name_mapping_test.cc"
    },
    {
      "type": "add",
      "old_id": "0000000000000000000000000000000000000000",
      "old_mode": 0,
      "old_path": "/dev/null",
      "new_id": "1b9a71802454cdb6b9f0532efbe157cc28a6b4fa",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/parallel_scan_reader_test.cc"
    },
    {
      "type": "modify",
      "old_id": "5cf47253221d0363c1f5437f45bb7b5eee8d4c13",
      "old_mode": 33188,
      "old_path": "src/iceberg/test/table_scan_test.cc",
      "new_id": "ecca97462279a050136cfd605545ad6c408a4e70",
      "new_mode": 33188,
      "new_path": "src/iceberg/test/table_scan_test.cc"
    }
  ]
}
