Skip to content

arrow-output: Expose row_group_size setting - #107897

Open
tomasfarias wants to merge 12 commits into
ClickHouse:masterfrom
tomasfarias:arrow-output/expose-row-group-size-setting
Open

tomasfarias wants to merge 12 commits into
ClickHouse:masterfrom
tomasfarias:arrow-output/expose-row-group-size-setting

Conversation

@tomasfarias

@tomasfarias tomasfarias commented Jun 18, 2026 •

Copy link
Copy Markdown

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 manipulate cap 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 cap 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, like output_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):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add a setting output_format_arrow_row_group_size to set a maximum number of rows for each record batch emitted from each ClickHouse block when using Arrow or ArrowStream output format.


Workflow [PR]
Sync PR [sync-upstream/pr/107897]

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.
@CLAassistant

CLAassistant commented Jun 18, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@tomasfarias
tomasfarias marked this pull request as ready for review June 18, 2026 17:49
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Jun 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [30956e1]

Summary: ✅


AI Review

Summary

This PR exposes output_format_arrow_row_group_size for Arrow and ArrowStream, wires it into the IPC writer, and adds focused coverage for the simple split and 0-rejection cases. The basic path looks right, but one batching interaction and one remaining documentation gap still need attention before the change is ready.

Findings

⚠️ Majors

  • [src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockOutputFormat.cpp:408-423] output_format_arrow_row_group_size is enforced only after consume has already decided to flush a staged chunk for output_format_arrow_record_batch_size / output_format_arrow_record_batch_size_bytes. With max_block_size = 1, output_format_arrow_record_batch_size = 4, output_format_arrow_row_group_size = 3, and six rows, the current path emits [3, 1, 2] instead of two full [3, 3] batches, so the new cap defeats the existing coalescing settings and creates extra tiny record batches even though more rows are immediately available.
    Suggested fix: make the cap participate in the staging threshold, or keep the overflow remainder staged after splitting so the next small block can fill it.

💡 Nits

  • [src/Processors/Formats/Impl/ArrowIPC/ArrowIPCBlockInputFormat.cpp:1568-1585] The Arrow docs table was updated, but the parallel ArrowStream docs table still omits output_format_arrow_row_group_size. Users reading the ArrowStream page still cannot discover the new setting there.
    Suggested fix: add the same output_format_arrow_row_group_size row to the ArrowStream format-settings table.
Tests
  • ⚠️ Missing a regression that combines output_format_arrow_row_group_size with output_format_arrow_record_batch_size or output_format_arrow_record_batch_size_bytes; the current new test only covers the no-coalescing path, so the batching interaction above would not fail.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit 30956e1.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.50% 79.50% +0.00%

Changed lines: Changed C/C++ lines covered: 45/46 (97.83%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-feature Pull request with new product feature label Jun 18, 2026
Comment thread src/Formats/FormatFactory.cpp Resolved
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"(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/Core/FormatFactorySettings.h Resolved
@tomasfarias
tomasfarias force-pushed the arrow-output/expose-row-group-size-setting branch from 526398b to 4421faa Compare June 19, 2026 21:29
@tomasfarias

Copy link
Copy Markdown
Author

Had some conflicts to resolve with master + I had not made the test file executable. These two problems should now be addressed after a local rebase (I initially messed up when using the GitHub UI).

Comment thread src/Core/FormatFactorySettings.h Resolved
@tomasfarias
tomasfarias force-pushed the arrow-output/expose-row-group-size-setting branch from 33b0214 to 09c013a Compare June 20, 2026 00:15
…aximum

Rather than providing an accurate number of rows per batch, we are capping
the rows per batch using the new setting.
@tomasfarias
tomasfarias force-pushed the arrow-output/expose-row-group-size-setting branch from 09c013a to c284513 Compare June 20, 2026 00:18
@clickhouse-gh

clickhouse-gh Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.30% 85.30% +0.00%
Functions 92.50% 92.50% +0.00%
Branches 77.50% 77.50% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 41/41 (100.00%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@tomasfarias

Copy link
Copy Markdown
Author

Current CI failure on Stress test (arm_ubsan) seems unrelated to this PR's changes. The failing query's log comment points to 03392_crash_group_by_use_nulls.sql.

I'll ignore it for now, but do let me know if I should rebase master or act in some other way.

Thank you!

@abashkeev abashkeev added the comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). label Sep 4, 2026
…-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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@clickhouse-gh

clickhouse-gh Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 30956e14c with master 199f114be (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

22 translation units recompiled, 88 s compile time in total, 22 of them have a recent master baseline.

Job report

@maxknv maxknv added the external Author is not a member of the ClickHouse organization label Nov 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-formats Input/output formats (CSV/JSON/Parquet/ORC/Arrow/Protobuf/etc.). external Author is not a member of the ClickHouse organization pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants