Repository navigation
fix(parquet): cap byte-budget level windows by value count - #11996
Conversation
Ratio-sized level windows assume nulls are spread evenly through a chunk. When values cluster ahead of a run of nulls, one window can hold every value, so the dictionary page grows past the format's 2 GiB page limit before its spill check runs. Cap each level window at twice the value budget so the documented two-values-per-page bound holds for any null layout. Closes apache#11994 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
run benchmark arrow_writer |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 1 (1 workers). Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
@sdf-jkl wdyt? |
|
run benchmark arrow_writer |
|
🤖 Benchmark starting (GKE) | trigger Target: arrow_writer Sharding factor: 4 (4 workers). Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Results will be posted when all workers finish. File an issue against this benchmark runner |
|
🤖 Benchmark failed or incomplete (GKE) | trigger Target: arrow_writer Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 1
Errors / missing shardsPer-runner informationarrow_writer — shard 1/1Node: gk3-benchmark-cluster-nap-1fzug0kq-c69560ca-b6ps Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource UsageNo completed measurement resource samples. File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Target: arrow_writer Comparing fix-11994-dict-overflow (0336bf8) to 9ffd63d (merge-base) diff Run configurationrun benchmark arrow_writer
shards: 4
Comparison results: View the complete native critcmp output. The comparison is published in an unlisted Gist because the original inline report exceeded GitHub's comment limit. Per-runner informationarrow_writer — shard 1/4Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-h5nx Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 2/4Node: gk3-benchmark-cluster-nap-jeel64w1-66f44736-l628 Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 3/4Node: gk3-benchmark-cluster-nap-1fzug0kq-50073869-jzxw Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
arrow_writer — shard 4/4Node: gk3-benchmark-cluster-nap-1fzug0kq-c69560ca-b6ps Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench arrow_writerCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
Benchmark summary:
The +4% comes from the new per-window cap scanning def levels; everything else is noise. #11997 removes a scan of the same def levels, so with both merged the sparse case is faster than |
|
yep, thanks for the review. LGTM and we can work on that one. |
…e#11997) # Which issue does this PR close? - Related to apache#11994 / apache#11996: this is a follow-up perf tweak, not the fix itself. # Rationale for this change `ByteBudgetChunker::byte_budget_sub_batch` calls `chunk_def.value_count(...)` before it asks the encoder whether the chunk's values fit the page budget. For nullable columns (`Materialized` def levels) that call is an O(chunk_size) scan, and it runs on every chunk of every nullable byte-array column, even chunks far below the page limit. # What changes are included in this PR? The chunker now asks the encoder first, about the next `chunk_size` values. That window always contains the chunk's values as a prefix, because a chunk holds at most `chunk_size` values. `count_values_within_byte_budget[_gather]` counts how many *leading* values fit, so its answer for the window also answers for the chunk: - **The whole window fits:** the chunk fits too. Return `None` without scanning def levels. This is the common case, and it uses the existing stage-1 bounds. Those cost O(1) for view arrays and one ordered pass over the indices for offset arrays. - **The count stops at `k`, the first value that overflows:** only now run `value_count`. If `k >= vals_in_chunk` the overflow is past this chunk, so the chunk fits. Otherwise `k` is the same answer the current code computes. The lookahead is used only on the gather path (`value_indices`), which the arrow writer always uses, because every gather index names a real value. A contiguous `values` slice from a raw `ColumnWriter` caller may be padded with placeholder `ByteArray`s past the values its levels reference, and those can't be sized. That path keeps counting the chunk's values first, as on `main`. There are no new trait methods. An earlier revision of this PR added a byte-array-only `values_fit_within_byte_budget_gather` hook to `ColumnValueEncoder`. This version reuses the existing count instead, and benchmarked the same. # Are these changes tested? New unit tests in `byte_budget_chunker` call `pick_sub_batch` directly, through both the contiguous and the gather entry points: - a small chunk is not split; - an overflow past the chunk, inside the lookahead window, does not split it; - an overflow inside the chunk splits it, with the same `Levels` window as on `main`; - an all-null chunk is not split; - a contiguous slice padded with placeholder values past the chunk is never read (`test_write_statistics_not_arrow` in `tests/geospatial.rs` caught this in CI). They pass on `main` as well, so they pin the behaviour to `main`'s. The second test fails if the `k >= vals_in_chunk` check is removed. The existing writer and page-size tests also pass. Benchmarks: `arrow_writer`, `/default` props, on a quiet GCE c3-standard-8. Each variant ran twice, interleaved, and the numbers below are the two runs: | case | main | this PR | | --- | --- | --- | | byte_array_sparse_99pct_null | 10.6 / 10.7 ms | 9.3 / 9.3 ms (**−13%**) | | string_and_binary_view | 52.9 / 52.6 ms | 51.7 / 51.5 ms | | string | 150.9 / 152.9 ms | 149.6 / 149.5 ms | | string_dictionary | 74.4 / 74.4 ms | 73.8 / 73.6 ms | | string_ree_95pct_null | 31.3 / 31.2 ms | 31.1 / 30.9 ms | | string_non_null | 176.4 / 179.7 ms | 175.7 / 176.0 ms | | large_string_non_null | 58.1 / 58.0 ms | 58.1 / 57.9 ms | | list_string_ree | 137.7 / 137.6 ms | 138.9 / 138.9 ms | Every case except the sparse one is within noise. `perf` on `byte_array_sparse_99pct_null`: `byte_budget_sub_batch` (with the inlined def-level scan) drops from 10.2% to 0.6% of samples, and `count_values_within_byte_budget_gather` rises from 0.9% to 1.6%. # Are there any user-facing changes? No. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Which issue does this PR close?
Rationale for this change
SubBatchStrategy::Levelsturns a value budget into a level count using the chunk's average level:value ratio. That ratio says nothing about how many values a single window holds. If 28 large values come before 996 nulls, the first 37-level window contains all 28 values, so the dictionary page reaches about 2.2 GB before the spill check runs. That breaks the "at most two values per page" bound described in #10554.What changes are included in this PR?
SubBatchStrategy::Levelsnow carries amax_valuescap (twice the value budget) alongside the level count.write_granular_chunkends each level window at whichever comes first: the level count, or the point wheremax_valuesvalues have been seen. It reuseswindow_end_for_valuesto find that point.Materializeddef levels on the granular (large-value) path.Are these changes tested?
Yes.
test_column_writer_caps_dictionary_page_size_with_clustered_nullsis a scaled-down version of the issue's reproducer: 28 distinct 64 KiB values, then 996 nulls, with a 64 KiB dictionary page limit. It fails without the cap (the dictionary page holds all 28 values) and passes with it.Are there any user-facing changes?
No API changes. Writers with clustered nulls and large values now produce bounded pages instead of failing with
Page uncompressed size overflow.🤖 Generated with Claude Code