Repository navigation
Conversation
d83aaf5 to
a82fb92
Compare
writeColumnImpl bit off a batch by row count alone (output_format_parquet_batch_size, 1024 rows), whatever those rows weighed, so 1024 values of a few MB reached the encoder as one multi-gigabyte batch and overran two separate 32-bit limits. arrow keeps the dictionary of BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY in a BinaryBuilder addressed with 32-bit offsets. The existing fallback to plain encoding asked whether the dictionary had grown too big only after Put, so a batch over that limit threw inside Put before the fallback could run. Checking before Put is not enough on its own: the same batch then becomes one data page, whose size is 32-bit as well, and the write fails with `Uncompressed page is too big` instead. A batch is now cut at the first record boundary at or after 64 MiB, far above any page a caller would ask for, so ordinary data comes out byte for byte as before. A record that would not fit a page at all is split wherever it happens to be, and the column and offset indexes are dropped for that chunk, because neither can describe pages that start mid-record. The dictionary check is also made before Put and extended to FIXED_LEN_BYTE_ARRAY, which shares that builder.
A JSON value's size is not the column's byteSizeAt: that counts the values but neither the keys nor the punctuation serialization writes out, and ColumnObject reports no serialized size at all. Cutting the batch after conversion therefore let ConverterJSON materialize the whole batch first. ConverterJSON now stops at a byte budget and reports how much of the batch it produced, including for repeated carriers, where the batch gives back the tail of the record it stopped inside. A record that wants more than the budget is converted whole, and only that record rather than the rest of the batch behind it. Its buffers grow with what it produced instead of with what it was asked for. Batches are also budgeted by what the encoding writes rather than by payload alone - plain BYTE_ARRAY prefixes every value with its 4-byte length - and every physical type is budgeted, not only the two byte-array ones: Array(UInt64) of 280 million elements failed with `Uncompressed page is too big: 2240000022`. Writing 1024 rows of ~2.1 MB JSON goes from 101s to 12s; the same as Array(JSON) from 369s to 21s.
a82fb92 to
9dd1c52
Compare
|
Workflow [PR], commit [268474e] Summary: ❌
AI ReviewSummaryThis PR bounds Parquet write batches by bytes, adds self-budgeting to the Missing context / blind spots
Findings
Final Verdict
LLVM Coverage Report |
| } | ||
| } | ||
|
|
||
| if constexpr (std::is_same_v<ParquetDType, parquet::ByteArrayType>) |
There was a problem hiding this comment.
The byte cap only runs before conversion for BYTE_ARRAY, but getBatch below still sees the full record size for every converter that owns staging storage. That leaves the same failure mode on widening / transformed paths such as UInt8/UInt16 -> INT32, DateTime64 -> INT64, UUID, Decimal*, UInt128/UInt256, and FixedString -> FIXED_LEN_BYTE_ARRAY: a single wide row still makes getBatch allocate count-sized buf / data_buf before lines 1361-1377 get a chance to shrink the batch.
So the new invariant from the PR body ("every physical type is budgeted") does not hold yet. This needs either an early byte cut for every converter with temporary storage, or the same self-budgeting hook that ConverterJSON now implements.
| def_count = def_count_kept; | ||
| data_count = values_in(def_count_kept); | ||
|
|
||
| converter.setByteBudget(max_record_bytes); |
There was a problem hiding this comment.
Retrying the first oversized record under max_record_bytes still leaves this path unbounded on value count, because ConverterJSON only budgets chars. For Array(JSON) with one high-cardinality row of tiny scalars, this retry can keep the whole row (the encoded page is still well below the 2 GiB split threshold) while lengths and buf grow for every element in the row. That turns a sub-2 GiB page into multi-GiB staging before limit_batch_by_bytes gets a chance to cut anything, so the new "budgeted converter" invariant is still false for high-cardinality rows.
This needs either a second budget on per-value metadata or the same "drop the page index and split the row" fallback once the retry itself would exceed the staging budget.
|
Closing. #122482 supersedes the core batch fix; the |
…ch cut Addresses the AI review blockers on this PR. `limit_batch_by_bytes` counted only the payload of a `BYTE_ARRAY` value, while plain encoding also writes a 4-byte length prefix per value, so a repeated record of many small values could stay below `max_record_bytes` and still build a page past `INT32_MAX`. The cut now measures `4 + len` per value; the returned total stays payload-only because it feeds `unencoded_byte_array_data_bytes`. Fixed-width physical types were not budgeted at all, so one huge `Array(UInt64)` record still reached `encoder->Put` whole. They are now budgeted by `sizeof(c_type)`; a batch that cannot reach the budget skips the walk, so ordinary columns pay nothing. Both changes are ported from ClickHouse#120538. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Depends on: #120028
Related: #120027
Carries #120028 as its first commit until that lands, since a pull request based on another branch
gets no CI here.
#120028 bounds a batch by the bytes it holds, measured after conversion. That is too late for a
converter whose cost cannot be predicted from the column: a
JSONvalue's size is notColumnObject::byteSizeAt, which counts the values but neither the keys nor the punctuationserialization writes out.
ConverterJSONnow stops at a byte budget and reports how much of thebatch it produced, and its buffers grow with that rather than with the count it was asked for.
JSONArray(JSON)Array(UInt64), 280M elementsUncompressed page is too big: 2240000022Batches are also measured by what the encoding writes rather than payload alone, since plain
BYTE_ARRAYprefixes every value with its 4-byte length, and every physical type's batch is boundedbefore it reaches a page. Only
BYTE_ARRAYandJSONare cut before conversion, though: convertersthat stage widened or transformed values (
UInt8/UInt16,DateTime64,UUID,Decimal*,UInt128/UInt256,FixedString) still allocate staging for the whole batch before the cut. Thatcosts memory on a wide row, not correctness, and is left to a follow-up. Two invariants here are argued rather than demonstrated: reaching
the page limit through those prefixes alone needs upwards of 16.7M values in one record, and the
fixed-width case 2^28, and building either costs more than 18 GB, so neither is in the test.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Parquetoutput spending minutes and gigabytes on wideJSONvalues, and failing withUncompressed page is too bigfor a row holding more than 2 GiB of fixed-width values. Batches are now bounded by what serializing and encoding them costs.Workflow [PR]
Sync PR [sync-upstream/pr/120538]