Repository navigation
Conversation
|
IMHO, I don't think this is the right direction. It makes unnecessary copies of schemas even when we don't have any list columns. I think a better approach would be asking file format readers to always respect |
ProjectionContext::Make now takes the reader's physical input Arrow schema and builds its reusable projection state from it. The context owns deep copies of the input and output Arrow schemas: each selected output field becomes a deep copy of its physical counterpart, preserving the physical layout, nested list offset widths, metadata, and type-specific flags such as sorted map keys, while only top-level names and nullability come from the projected schema. The borrowed logical-schema pointers and their accessors are removed, so schema inputs are only used during construction. FileScanTaskReader::Open resolves the physical schema before emitting any batch so pass-through, filtered, and projected batches all match the schema reported by the stream, including files that mix list and large_list layouts. Tests cover both projection backends (nanoarrow and Arrow compute): mixed list layouts, sorted-map flags under nullability changes, zero-column projections, and 36 task-reader scenarios that destroy the reader before consuming the stream and validate retained batches after the stream is released.
6344250 to
536f372
Compare
Ans: Agreed. I reject the invalid schema. In the new implementation, the The Avro reader errors out when use-large-list=true meets any projected list. Test cases are also added for this new behavior. |
wgtmac
left a comment
There was a problem hiding this comment.
Thanks @kamcheungting-db for the nice cleanup! I think the comment s are too verbose perhaps we can refactor or remove them in a separate PR.
… group planning (#1113) ## What this PR does Adds task-group planning for parallel scans, on top of the byte ranges from #976 and the range-aware Parquet reads from #1002: - `DataTableScan::PlanTasksStream()` — lazy, fallible stream of `FileScanTaskGroup` - `DataTableScan::PlanTasks()` — the same, collected into a vector Eligible Parquet files are split into byte ranges, and the tasks are packed into groups of roughly `read.split.target-size` bytes. ## How it works ``` PlanFilesStream() | v Whole Parquet file larger than target? -- no --> keep task as is | yes v Valid manifest split_offsets? | yes | no v v merge intervals fixed-size byte ranges toward target (shorter final range if needed) | | +---------+----------+ v pack tasks into groups | v FileScanTaskGroup stream ``` **Packing** — follows Java Iceberg’s first-fit and eviction rules: - task weight = `max(range bytes + delete content bytes, (1 + delete files) * open-file-cost)`; a deletion vector counts its blob size, not its container file size - a task joins the first open group that still fits - at most `planning-lookback` groups stay open; when a new one opens, the largest open group is closed first - at most 1,024 tasks per group; a task heavier than the target becomes its own group **Files that stay whole:** files at or below the target size, non-Parquet files, and Parquet files whose valid manifest offsets yield only one range. ## Settings | Property | Default | Resolves from | |---|---|---| | `read.split.target-size` | 128 MB | scan option > table property > default | | `read.split.planning-lookback` | 10 | same | | `read.split.open-file-cost` | 4 MB | same | Malformed or invalid values fail planning before any planning work starts. ## Stream behavior Single pass, lazy, owns the underlying task stream and its metrics, and can outlive the scan. An executor set with `PlanWith()` is borrowed and must stay alive until the group stream is destroyed. Destroying the stream mid-consumption releases all planning resources. The stream retains the current file’s remaining splits across calls to `Next()`. Splitting requires no data-file I/O or Parquet bundle registration. ## Tests - `table_test` (core-only, includes `ScanTaskPlanningTest`): split coverage and merging, delete files and residual filters carried into every split, mixed Parquet/Avro groups, the Java weight formula, group packing (first fit, lookback, 1,024 cap, oversized singleton), settings precedence and errors, incremental consumption, early destruction. - Bundled `scan_test`, across manifest format versions: split offsets used with no footer read (the file path does not exist), fixed-size ranges for missing or invalid offsets, files at or below target stay whole, every row read exactly once across splits, scan option beats table property, no-snapshot scans, delete files carried into every split. `pre-commit` is clean. ## Related Part 1 #976 · Part 2a #1002 · Part 2b #1062 · Part 2c #1065. The bounded parallel reader and end-to-end validation follow in later parts.
Problem
A
FileScanTaskReaderstream uses the merge-on-read path whenever a task carries v2 position or equality deletes (or, since #1065, an enforced residual filter). That stream used to declare its schema by converting the logical Iceberg projected schema withToArrowSchema(), which always yields the canonical Arrow layout (e.g. 32-bitlist).The batches it emits, however, follow the physical layout produced by the file reader, which could legitimately differ:
ReaderProperties::kArrowUseLargeListasks the Parquet reader forlarge_list(64-bit offsets),ARROW:schemametadata can store a mix oflistandlarge_list,So one and the same stream could emit two different physical layouts at once:
What this PR does
Rather than tracking whatever layout a file happens to store, this PR pins the stream to one configured layout and enforces it end to end:
read.arrow.use-large-listnow applies to every projected list — including nested lists — in every reader, not just the Parquet reader.ARROW:schemaconflicts with the setting fails withNotSupported, naming the setting and the offending field path — list offset widths are never converted;use-large-list=truewhenever the projected schema contains a list (Avro supports only 32-bit list).How it works
Key changes
ToArrowSchema(schema, out, use_large_list = false)— the width applies to every list, nested included.ProjectionContext::Make(input_schema, output_schema, project_batch_function, validate_batch = true, use_large_list = false):Schema*members and the old overloads are gone; accessors return the owned schemas;UseLargeListType,AlignTypeToReader,AlignFieldsToReader— ~150 lines) is replaced by a smallValidateListTypescheck that rejects a conflicting stored layout up front.use-large-list=truemeets any projected list.Reader::Schema()now documents its contract: every batch must match this schema and the configured list width; readers must reject unsupported widths before emitting any batch.TaskStreamSource: deletes, residual filters (feat(data): enforce residual filters in the task reader #1065), and projection share oneProjectionContext; it no longer cachesreader_->Schema()or stores borrowed schemas, andSchema()returns an independent deep copy on every call, so results stay valid after the stream is released.Design note: an earlier iteration of this PR instead copied the reader's physical schema (including mixed stored layouts) into the projection. The final design deliberately trades that flexibility for a strict, simple contract — one configured width, enforced everywhere — because a stream that silently mixes 32- and 64-bit offsets is a data-correctness hazard, and converting between widths hides what the file actually stores.
Testing
arrow_c_data_util_test.cc— both projection backends (nanoarrow and Arrow compute):ConfiguredListWidthsWithBothBackends— nested lists follow the configured width through selection and reordering;EmptyProjectionPreservesRowCount— a zero-column projection keeps the alive row count;ValidateBatchControlsNonMonotonicStringOffsets,SkippedContentValidationStillRejectsInvalidStructure,MovePreservesValidateBatch— thevalidate_batchknob behaves as documented;ToArrowSchemaTest.ConfiguredListWidthsInNestedTypes— the width reaches nested lists.LargeListSettingRejectsMissingNestedLists,LargeListSettingRejectsOnlyProjectedLists.file_scan_task_reader_test.cc:EmptyProjectionPreservesLiveRowCount— position deletes plus a zero-column projection still stream the correct number of live rows;FileScanTaskPhysicalSchemaTest— 64 scenarios: 8 delete-batch selections (delete first row / a second-batch row / no-op / whole first batch / all rows / empty split / no deletes / position deletes) x {all columns, pruned} x {list, large_list, stored-mixed schema, stored-mixed large-list schema}. Stored layouts that conflict with the setting are rejected withNotSupportednaming the setting and the offending column (e.g.nested.tags); every other scenario checks the declared schema before, between, and after batches; imports every batch against it; destroys the task reader before consuming the stream; and re-validates the retained batches after the stream is released.Local validation:
data_test,parquet_test,avro_test,arrow_test,scan_test, andschema_testpass;pre-commit(clang-format included) is clean;clang-tidy 22.1.8(the version CI pins) reports no findings on changed lines.Related