Repository navigation
arrow-output: Expose row_group_size setting - #107897
tomasfarias wants to merge 12 commits into
Conversation
Currently, there is no direct way to manipulate the number of rows ClickHouse includes in a record batch when writing to Arrow or ArrowStream formats. max_block_size and min_insert_block_size can be used, with varying degrees of success, but these settings affect a lot of other ClickHouse functions, beyond just writing Arrow record batches. So, a solution to specifically control Arrow/ArrowStream record batch size is desired. There is already a row_group_size setting for Arrow/ArrowStream; however this is not mutable, but hardcoded to 1 million. This commit just exposes the setting like any other Arrow/ArrowStream setting, preserving the 1 million as default. Additionally, we validate that the setting is not 0, and throw an exception if that's the case.
|
Workflow [PR], commit [30956e1] Summary: ✅
AI ReviewSummaryThis PR exposes Findings
💡 Nits
Tests
Final VerdictChanges requested. LLVM Coverage ReportMeasured on commit 30956e1.
Changed lines: Changed C/C++ lines covered: 45/46 (97.83%) · Uncovered code |
| DECLARE(Bool, output_format_arrow_unsupported_types_as_binary, true, R"( | ||
| Output types having no conversion as raw binary data. If false - such types would raise UNKNOWN_TYPE exception. | ||
| )", 0) \ | ||
| DECLARE(UInt64, output_format_arrow_row_group_size, 1000000, R"( |
There was a problem hiding this comment.
This adds a user-facing Arrow output setting, but the source-level format documentation table for Arrow/ArrowStream still lists the other output_format_arrow_* settings and omits output_format_arrow_row_group_size (src/Processors/Formats/Impl/ArrowBlockInputFormat.cpp). Please add the new row there as well, otherwise users reading the format docs will not discover the setting from the Arrow/ArrowStream page.
There was a problem hiding this comment.
I've updated the documentation table. To be honest, I did not think to look in the input file as this is purely an output setting.
There was a problem hiding this comment.
Re-checking the current head: the new row was added to the Arrow settings table at src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockInputFormat.cpp:1447, but the parallel ArrowStream table starting at src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockInputFormat.cpp:1568 still stops at output_format_arrow_use_signed_indexes_for_dictionary and never lists output_format_arrow_row_group_size. Users reading the ArrowStream page still cannot discover the new setting there, so this thread is not fully resolved yet.
526398b to
4421faa
Compare
|
Had some conflicts to resolve with |
33b0214 to
09c013a
Compare
…aximum Rather than providing an accurate number of rows per batch, we are capping the rows per batch using the new setting.
09c013a to
c284513
Compare
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 41/41 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
Current CI failure on Stress test (arm_ubsan) seems unrelated to this PR's changes. The failing query's log comment points to I'll ignore it for now, but do let me know if I should rebase master or act in some other way. Thank you! |
…-row-group-size-setting Resolve the conflict with the move of the settings changes history into the setting declarations (ee6b44f): the history records this PR added to `SettingsChangesHistory.cpp` now live as trailing arguments of the `DECLARE` of each setting. - retargeted PR record [email protected] to 26.10 (settings-history check rule) - semantic merge fixes in non-conflicting files: src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockInputFormat.cpp, src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockOutputFormat.cpp, src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockOutputFormat.h Also resolved conflicts in: - `src/Formats/FormatFactory.cpp` - `src/Processors/Formats/Impl/ArrowBlockInputFormat.cpp` - `src/Processors/Formats/Impl/ArrowBlockOutputFormat.cpp` Master removed the library-based Arrow writer, so the row-group size limit and its zero check are ported into `ArrowIPCBlockOutputFormat`. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
| { | ||
| /// `output_format_arrow_row_group_size` caps the rows of one record batch: a larger chunk (a large | ||
| /// incoming block, or a combined batch) is split into several batches. Smaller chunks are not combined here. | ||
| const size_t max_rows = format_settings.arrow.row_group_size; |
There was a problem hiding this comment.
Because the cap is enforced only in writeChunk, after consume has already flushed once output_format_arrow_record_batch_size or output_format_arrow_record_batch_size_bytes fires, the overflow from one split batch is never carried into the next batch. With max_block_size = 1, output_format_arrow_record_batch_size = 4, output_format_arrow_row_group_size = 3, and six rows, this path stages rows 1..4, emits [3, 1], and then finalizes with [2] instead of two full [3, 3] batches. That defeats the existing coalescing settings whenever their target is above the new cap, producing extra tiny record batches and metadata overhead even though more rows are immediately available. The cap needs to participate in the flush threshold, or the split remainder needs to stay staged for the next source block.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units22 translation units recompiled, 88 s compile time in total, 22 of them have a recent master baseline. |
I couldn't find any issues or PRs about this when using the usual GitHub search functions.
Problem
Currently, there is no direct way to
manipulatecap the number of rows ClickHouse includes in a record batch when writing to Arrow or ArrowStream formats. max_block_size and min_insert_block_size can be used, with varying degrees of success, but these settings affect a lot of other ClickHouse functions, beyond just writing Arrow record batches. So, a solution to specificallycontrolcap Arrow/ArrowStream record batch size is desired.There is already a row_group_size setting for Arrow/ArrowStream passed to the underlying Arrow library functions when writing batches; however this is not mutable, but hardcoded to 1 million.
Changes
This commit just exposes the setting like any other Arrow/ArrowStream setting, preserving the 1 million as default.
Additionally, we validate that the setting is not 0, and throw an exception if that's the case.
Alternatives considered
I thought about a fully new setting, rather than overwriting
row_group_size. This would be better named, likeoutput_format_arrow_max_record_batch_size, but the diff would be bigger, so I kept it simpler. If this is preferred though I could go that way.AI disclosure
I am familiar with Arrow, and ClickHouse as a user, but not as much with the ClickHouse repo. So, I used GPT 5.5 to explore the repo and find where would this change be better located. I find it does a better job than GitHub's search tools.
The changes were then authored by me.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add a setting
output_format_arrow_row_group_sizeto set a maximum number of rows for each record batch emitted from each ClickHouse block when usingArroworArrowStreamoutput format.Workflow [PR]
Sync PR [sync-upstream/pr/107897]