Repository navigation
Bound a parquet write batch by bytes, not only by rows - #122482
Conversation
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. The budget only has to keep those 32-bit quantities out of reach, so it sits far above any page a caller would ask for and ordinary data comes out byte for byte as it did before. The dictionary check is also made before Put and extended to FIXED_LEN_BYTE_ARRAY, which shares that builder.
The bound was only applied at record boundaries, because that is where pages have to start when the page index is written, and output_format_parquet_write_page_index is on by default. A single Array(String) row larger than 2 GiB therefore stayed in one batch and still failed with `Uncompressed page is too big`. Such a record is now split at 1 GiB wherever it happens to be. Neither the column index nor the offset index can describe a chunk whose pages start mid-record, so both are dropped for it rather than written wrong: the offset index addresses whole rows through first_row_index, and a continuation page has no row of its own to point at.
The threshold was 1 GiB, well below the page size that forces the split, so a record between 1 GiB and 2 GiB was split and lost its page index even though master writes it whole with a valid one. It is now just under the limit that makes the split necessary, so only a record that would otherwise fail to write is affected.
The test timed out on the stateless runs. It peaked around 15 GB: the oversized record was built by mapping over a range of 2200 million-byte strings, and read back with a GROUP BY on a 2.2 GB array. The record is now collected with groupArray over many small values, which costs 4.7 GB, and the read backs no longer group by a huge value or take uniqExact over one - a hash of it answers the same question. Runtime goes from 12s to 3s locally. The record still holds 2.2 GB, more than a page can address, so it is still split: with the bound disabled the write fails with `Uncompressed page is too big: 2208800020`.
limit_batch_by_bytes ran on the converted values, so the converter had already built the whole batch by the time it was measured. ConverterJSON serializes each value into storage of its own, which meant a batch of wide Object values was materialized in full before being shrunk. The batch is now cut from the source column's sizes first, and measured again afterwards because serializing a value can grow it. Writing 1024 rows of ~2.1 MB JSON goes from 101s to 12s and from 7.58 GB to 6.62 GB peak RSS.
Cutting the batch from ColumnObject::byteSizeAt does not work: it counts the values but not the keys or the punctuation SerializationJSON writes back out, which is why getSerializedValueSize returns nullopt for it. Rows with many long keys and small values stayed under the cut and were still materialized in full. ConverterJSON now stops serializing once the batch reaches the budget and reports how much of it it produced, and the caller shrinks the batch to that. Only for a column with no repetition levels: a shorter batch has to stay a whole number of records when pages follow record boundaries, and the values that would complete one have not been converted. Writing 1024 rows whose keys serialize to ~4 MB each goes from 382s and 4.88 GB peak RSS to 19s and 0.66 GB. The wide `JSON` case in 05175 now uses long keys, which is the shape the source column's own size does not see.
The budget was only given to a column with no repetition levels, so Array(JSON) and Map(..., JSON) went back to being cut by ColumnObject::byteSizeAt, which does not measure what serializing a value costs. The converter is bounded for those as well now. Where pages follow record boundaries the batch gives back the tail of the record it stopped inside, and a record that wants more than the budget on its own is converted whole, because it cannot be split. Writing 1024 rows of Array(JSON) whose keys serialize to ~4 MB each goes from 369s to 21s. Peak RSS is unchanged at 8.4 GB for that query: it is the values themselves, not the converter's buffer, and bounding the batch does not make the column smaller.
When the converter stopped inside the first record of the batch, the fallback asked it for the whole provisional batch again without a budget. That batch is write_batch_size values extended to the end of a record, so everything behind the first row was serialized as well, and then dropped by the cut that follows. Only the first record is converted now. On 11 rows of 100 JSON values of ~700 KB, where one batch covers every row: 19s and 3.04 GB peak RSS before, 10.5s and 0.79 GB after, and the file is byte for byte the same.
Plain BYTE_ARRAY prefixes every value with its 4-byte length, and the cuts counted only the payload. A record of many small values - FixedString written as BYTE_ARRAY reaches this, with output_format_parquet_fixed_string_as_fixed_byte_array = 0 - can therefore stay under max_record_bytes while the page it builds does not fit. Both cuts now add the per-value overhead: 4 bytes for BYTE_ARRAY, none for FIXED_LEN_BYTE_ARRAY, which writes values back to back. The total they return is still the payload alone, because that is what unencoded_byte_array_data_bytes reports.
…atch Only BYTE_ARRAY and FIXED_LEN_BYTE_ARRAY were budgeted, so a record of fixed-width values went to the encoder whole however large it was. Array(UInt64) of 280 million elements failed with `Uncompressed page is too big: 2240000022`; it writes now. A batch of write_batch_size fixed-width values is a few kilobytes, so ordinary columns never reach the cut. ConverterJSON also sized buf and stash from the number of values it was asked for, which for a repeated carrier is the whole record however many values that is - allocating for all of them before the budget could stop the loop. It now appends the serialized values to one buffer and hands out pointers into it once that buffer has stopped growing, so both it and the lengths grow only as far as the budget allows.
The retry disabled the budget outright, so a record larger than a page was serialized whole however large it was - which for JSON the source column's size does not predict. It is budgeted by max_record_bytes instead. A record that fits a page is converted whole as before; one that does not is cut where the budget runs out, which is what the split below would do with it anyway, at the cost of the page index. The converter's peak is then what a page can hold rather than whatever the record happens to be. Checked with the limits lowered to 8 MiB and 32 MiB against a 70 MB record: the write splits mid-record, the file reads back the same, and the retry stops at the budget instead of serializing the whole record.
This branch had grown two changes with different standing: the batch byte bound, which is demonstrable, and converter-level batching for JSON carriers, whose remaining invariants need more than 2 GiB inside one record and cannot be exercised by a test runner. Only the byte bound and the oversized-record split are left here. The converter work continues on parquet-json-converter-budget and opens once this lands, since it builds on this change.
Bounding the batch is not enough on its own: the page keeps taking batches until it reaches output_format_parquet_data_page_size, and that setting has no upper bound. Set near the 32-bit page limit, ordinary String data still reached `Uncompressed page is too big`. The page target is capped at the same limit a record is split on, so it no longer depends on the setting staying small. The default of 1 MiB is unaffected.
The page size was only checked after `encoder->Put`, against a target of 2 GiB - 64 MiB. A record can legally be almost that large on its own, so with a raised `output_format_parquet_data_page_size` a ~1.99 GB `Array(String)` record left the page just under the target, the next ~200 MB record went in whole, and the page failed with `Uncompressed page is too big: 2190016121`. When the page already holds data and the next batch's encoded size would push it past the limit, the page is flushed first and the batch starts the next one. The check runs before the batch's statistics and bloom filter hashes are accumulated, so nothing is attributed to the page it no longer joins. Dictionary-encoded pages hold only indices and are left alone.
…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 #120538. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The oversized-record case was killed on every CI run (`Stateless tests (arm_binary, sequential)` and the flaky check): `groupArray` plus parallel encoding, which hands the encoder a copy of the whole 2.2 GB column, peaked at 8.8 GB. Building the array with `arrayMap` and disabling `output_format_parquet_parallel_encoding` brings it to 2.5 GB, in line with the other cases. Also covers `FixedString` written as `BYTE_ARRAY`, which goes through the length-prefix budget. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120028&sha=d3c980b416ac2b57d32041db8c4da3fcd38c4ca9&name_0=PR PR: #120028 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Workflow [PR], commit [d664d62] Summary: ✅
AI ReviewSummaryThis PR bounds Missing context / blind spots
Findings
Final Verdict
LLVM Coverage ReportMeasured on commit d664d62.
Changed lines: Changed C/C++ lines covered: 154/164 (93.90%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes7 object files changed (+255.70 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units9 translation units recompiled, 29 s compile time in total, 9 of them have a recent master baseline. |
|
Thanks @alexey-milovidov for picking this up and carrying it over the line, and for the |
…parquet-batch-byte-bound
Address review: the batch cut and the pre-flush only counted the values, so a nested repeated column of narrow values could still build a page past the 32-bit page size. One row of `Array(Array(FixedString(1)))` with inner arrays of length 2 keeps about 2.08 GiB of values at the split point, and its repetition levels alone add about 520 MiB, so `flush_page` threw `Uncompressed page is too big`. The budget now adds the most the rep and def levels can take, the same bound `encodeRepDefLevelsRLE` reserves, and, with a dictionary, the most the RLE of the indexes can take for the dictionary size the batch may reach. The pre-flush applies to dictionary-encoded pages as well. An oversized record is now cut before the value that would carry the page past the bound rather than after it, so one wide value at the boundary cannot overshoot it either. All of these are worst cases, so pages of ordinary data stay as they were. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Ubuntu seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
…nce per block `mortonEncode` with two arguments ran one row loop for every argument type and mask: per row and argument it tested the mask and `is_const`, reloaded the ratio, switched on the column width and, with a mask, called the out-of-line `expand` (36 call sites in the arm `executeImpl`). On arm the speed of the branch-dense paths depends on the binary's layout, so `space_filling_curve` ClickHouse#1 (constant mask) and ClickHouse#4 (`UInt32` arguments) have per-build speed modes and flag unrelated PRs in Performance Comparison (ClickHouse#122482), while ClickHouse#2 (two `UInt64` columns) is stable. Now each argument is resolved once per call into a contiguous `UInt64` array with the range expansion applied: a `UInt64` column that needs no expansion is read in place, other widths are widened with one type dispatch, and a constant ratio is applied in one loop per ratio value (`expand` is `ALWAYS_INLINE` and called with a template-constant ratio, so its switch folds). A per-row mask keeps the per-row `expand`. `nd == 1` writes the result column directly. The encode loops only encode. x86, one core, median fix/base of 5 interleaved rounds over the queries of `space_filling_curve.xml`: ClickHouse#1 0.57 (BMI2) / 0.55 (lookup-table path, built with `-mno-bmi2`), ClickHouse#2/ClickHouse#3/ClickHouse#6 0.45-0.64, ClickHouse#4 0.86-0.88, untouched functions 0.99-1.03. Results are unchanged: 545 checksums over every width, mask and ratio are byte-identical before and after on both code paths, and the new test fails on both paths under two mutations of the change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…parquet-batch-byte-bound
…erflow` within CI memory The `FixedString(2100016)` case built a 2 GiB `String` column with `concat` and then converted it with `toFixedString`, whose output is rounded up to a 4 GiB allocation, so with both columns alive the query needed about 6 GiB and hit the 4.5 GiB limit in `Stateless tests (arm_binary, sequential)` and the flaky check. Padding the number itself with `toFixedString` keeps the 1024 values distinct and wide without the intermediate `String` column; the query now peaks at 2.6 GB RSS and the reference is unchanged. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122482&sha=470b8f048b927b87a57e3c5f991b0e93082a3991&name_0=PR PR: #122482 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master and fixed the @groeneai, thanks for #123354 on the ARM The CLA check is still red, and it needs a human decision. Two commits (0a31925 and 470b8f0) were made with a misconfigured identity, |
…parquet-batch-byte-bound
Address review: the byte budget was applied only after `getBatch` had materialized the whole record, so a converter that allocates per value (`ConverterFixedString`, `ConverterString`, `ConverterJSON`, ...) still allocated for every value of a huge repeated record, e.g. ~1.4 billion `FixedLenByteArray` pointers for one `Array(Array(FixedString(1)))` row. Now a record is extended into a batch only up to `max(write_batch_size, 65536)` values; the rest of it goes in following batches of the same page. A page is flushed only at a record boundary (unless it would grow past `max_record_bytes`), so pages still start where the page index says they do. For all types except `BYTE_ARRAY` the batch is cut by bytes before it is converted, since the value size is known without converting. The page index is invalidated in `flush_page` whenever a page ends inside a record, whichever check caused it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failures: |
|
All three have fixing PRs in progress; I checked each against the logs of the
The current head |
…parquet-batch-byte-bound
The fast test build has no `Parquet` format, so the test failed there with `Unknown format Parquet`. Tag it `no-fasttest`, and give it a number that does not collide with `05325_parallel_replicas_progress_total_rows` from master. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122482&sha=c19fe03e93d01e5942ab950401019995c885b98a&name_0=PR&name_1=Fast%20test #122482 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master and fixed the @groeneai, thanks for linking #123790, #123729 and #123695 for the three unrelated |
… to the byte cut `ConverterJSON::getBatch` serialized every row of the batch into its stash before `limit_batch_by_bytes` could cut it, so 1024 rows of ~2 MiB `JSON` were materialized as ~2 GiB of text before the batch was trimmed to ~64 MiB. The converter now serializes values one at a time on demand: the byte cut asks for each value's size in order, and only the values that end up in the batch are serialized. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`valueSize` is called per value by the byte cut of a `Parquet` batch, and `getDefaultSerialization` of `Object` rebuilds the typed-path serializations, so create it once in the constructor instead of on every call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05175_parquet_wide_values_no_32bit_overflow` is excluded from debug and sanitizer builds, which are the only builds the bugfix validation runs, so the fix could not be validated. The new test writes the same 1024 rows of ~2.1 MB with plain encoding and without compression, checksums, a bloom filter and the page index. On master it fails with `Uncompressed page is too big` (and aborts on an assertion in `writeFileFooter` in the debug build) after about 7 seconds of debug time; with the fix it round-trips. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122482&sha=933913101bf002595d381fe2f0feb4ffba2dea33&name_0=PR&name_1=Finish%20Workflow #122482 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Merged master and added |
…tch_plain_encoding` Reading the string column back peaks at about 5.6 GB of RSS, more than the 4.5 GiB memory limit of the CI runners, so the test failed with `MEMORY_LIMIT_EXCEEDED` in the read stage. The regression is in the writer, so check the result through `ParquetMetadata` and read only the narrow column. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122482&sha=latest&name_0=PR&name_1=Finish%20Workflow #122482 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Supersedes #120028 by @erezrokah, whose branch lives in an organization-owned fork that maintainers cannot push to. The original commits are kept, so the authorship stays with @erezrokah; thank you for the work and the thorough measurements.
Related: #120028
Related: #119300
Related: #120027
Related: #117754
Extended by: #120538
writeColumnImplbites off a batch by row count alone (output_format_parquet_batch_size, 1024rows), whatever those rows weigh, so 1024 values of a few MB reach the encoder as one
multi-gigabyte batch. That overruns the 32-bit offsets of the
BinaryBuilderbehind the dictionaryencoder, and then the 32-bit size of the data page.
Writing 1024 rows of ~2.1 MB:
StringFixedString(2100016)array cannot contain more than 2147483646 bytes, have 2148302982... have 2148316368Uncompressed page is too big: 2150407082A batch is cut at the first record boundary at or after 64 MiB, so ordinary data is written byte for
byte as before. A record that would not fit a page at all is split wherever it happens to be,
dropping that chunk's column and offset indexes, since neither can describe pages starting mid-record.
On top of #120028 this addresses the AI review blockers there, porting the relevant parts of #120538:
BYTE_ARRAYby what the encoding writes (4 + lenper value), not payload alone;sizeof(c_type), so one hugeArray(UInt64)record is split too;05175_parquet_wide_values_no_32bit_overflowno longer gets OOM-killed on CI: the oversized-record case peaked at 8.8 GB because parallel encoding copied the whole column; it now peaks at 2.5 GB. It also coversFixedStringwritten asBYTE_ARRAY.Array(Array(FixedString(1)))row) cannot push a page past the 32-bit size through its levels; the pre-flush covers dictionary-encoded pages too.max(output_format_parquet_batch_size, 65536)values, sogetBatchno longer allocates per value for the whole record before the byte cut; the slices go into the same page, which still ends on a record boundary. For all physical types exceptBYTE_ARRAYthe byte cut happens before conversion.JSONvalues are serialized one at a time during the byte cut, so only the values that make it into the batch are serialized, not the whole row-count batch.05338_parquet_wide_batch_plain_encodingwrites the same >2 GiB batch with plain encoding and no compression, checksums, bloom filter or page index, so it takes seconds in the debug build and lets the bugfix validation reproduce the bug (Uncompressed page is too bigon master), which05175cannot since it is excluded from debug and sanitizer builds.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Parquetoutput failing withCapacity error: array cannot contain more than 2147483646 bytesorUncompressed page is too bigwhen a batch of rows held more than 2 GiB ofStringorFixedStringdata. A batch is now bounded by bytes as well as by rows, which also lowers the peak memory of the write.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122482]
Version info
26.10.1.1873-master(included in26.10and later)