Skip to content

Iceberg bucket split by split offsets - #125636

Merged
scanhex12 merged 18 commits into
masterfrom
iceberg-bucket-split-by-split-offsets
Nov 4, 2026
Merged

scanhex12 merged 18 commits into
masterfrom
iceberg-bucket-split-by-split-offsets

Conversation

@scanhex12

@scanhex12 scanhex12 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Iceberg bucket split by split offsets. Do not use parquet metadata anymore - let's split file by split offsets from metadata


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

Version info

  • Merged into: 26.11.1.1357-master (included in 26.11 and later)

scanhex12 and others added 3 commits October 13, 2026 14:24
With `cluster_table_function_split_granularity = 'bucket'` the initiator read
the footer of every file to split it into row groups. When the size of a file
and the offsets of its row groups are known from the table metadata (Iceberg
`file_size_in_bytes` and `split_offsets`), the file is now cut into byte ranges
on these offsets without reading it, and a replica reads the row groups whose
middle falls into its range. The byte range is sent in the new cluster
processing protocol version 12. Files without `split_offsets` are split as
before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The number of row groups of a data file depends on the block sizes of the
insert, so the test checks that files were split rather than the exact number
of tasks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d9b99e2]

Summary: ✅


AI Review

Summary

The PR adds optional Iceberg bucket splitting using manifest split_offsets, avoiding initiator footer reads when the hints are usable, and introduces cluster-processing protocol version 15 for byte-range tasks. Reviewed head: d9b99e2654e042a5ae2caf2ac8d9c8c9cf005b40. The earlier count-only, count-cache, and mixed-version findings are addressed. ⚠️ Request changes: the existing protocol-specification finding remains unresolved.

Consumers of the new bucket representation traced in this review:

  • ClusterFunctionReadTaskResponse: negotiates the encoding version; older workers reject byte-range tasks explicitly.
  • Reader::selectRowGroups: converts byte ranges to row-group membership before normal decoding, statistics-only min/max, and TopN processing.
  • ParquetV3BlockInputFormat::read: selects row groups independently for count-only reads.
  • ObjectIteratorSplitByBuckets and filterByMatchingRowGroups: cache hits use footer-based row-group buckets.
  • StorageObjectStorageSource: excludes bucket reads from the per-file count cache; task identifiers distinguish byte ranges.
PR Metadata

💡 Improvement is appropriate, but its required changelog entry says Parquet metadata is no longer used. The optimization is disabled by default and retains footer-based paths. Replace the entry with:

Allow Iceberg cluster table functions to use manifest split_offsets for bucket splitting, reducing Parquet footer reads on the initiator. Enable with cluster_table_function_split_by_split_offsets=1 after upgrading every server in the cluster.

Missing context / blind spots
  • ⚠️ The current head's targeted integration job is pending; its report contains no result for test_cluster_table_function_bucket_split_by_split_offsets yet. No local server tests were run. A completed run of that test would confirm the multi-row-group aggregate and standalone count assertions.
Findings

⚠️ Majors

  • src/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp:615–623 — the native protocol specification does not describe the new encoding. Protocol version 15 appends a VarUInt byte-range presence flag after the row-group IDs and, when present, VarUInt offset and length. Even ordinary row-group buckets gain the zero presence flag at version 15. The existing specification at docs/resources/develop-contribute/native-protocol/protocol.mdx:172 and :523 still advertises version 14 and omits this change. Update the advertised version and document the gated fields, ordering, and restriction on older workers. This is the existing unresolved finding; no duplicate inline comment was posted.
Final Verdict

⚠️ Request changes. Update the native protocol specification for version 15 and correct the changelog entry. Current-head integration validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 13, 2026
scanhex12 and others added 2 commits October 13, 2026 15:01
…t-split-by-split-offsets"

This reverts commit 0b5cefc, reversing
changes made to a3e02d9.
The writing of `split_offsets` by ClickHouse goes in a separate pull request,
so the stateless test, which relied on it, is replaced by an integration test
on a file written by Spark, which always records `split_offsets`. The file is
read through `icebergS3Cluster` with `bucket` granularity, the result must be
the same as without the cluster, and the tasks must be byte ranges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added the comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. label Oct 13, 2026
scanhex12 and others added 6 commits October 15, 2026 13:04
`readMinMaxFromStatistics` came from master with the old
`std::optional<std::unordered_set<UInt64>>` row group filter, which no longer
compiles after this PR replaced it with `RowGroupSelection`. Also respect the
byte-range split when reading min/max from statistics.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125636&sha=77c8316d2fc0b4ac32fa6155a606b02523a4dda1&name_0=PR&name_1=Build%20%28arm_tidy%2C%204%2F4%29
PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`ParquetFileBucketInfo` is copied, and the implicit copy constructor of
`FileBucketInfo` is deprecated because of its user-declared destructor
(`-Wdeprecated-copy-with-dtor` in the clang-tidy build).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125636&sha=77c8316d2fc0b4ac32fa6155a606b02523a4dda1&name_0=PR&name_1=Build%20%28arm_tidy%2C%202%2F4%29
PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Byte range buckets cannot be sent to workers on an older cluster processing
protocol, so splitting by `split_offsets` by default made `bucket` reads fail
with `UNKNOWN_PROTOCOL` during rolling upgrades. Add
`cluster_table_function_split_by_split_offsets` (disabled by default) to enable
it once all servers are upgraded, and mention it in the exception message.

On a hit in the query condition cache, split by the footer instead, so that
`filterByMatchingRowGroups` can drop buckets without matching row groups.

PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ranges are cut on `split_offsets`, which writers set to the row group
starts, so assigning a row group by its start is enough and is simpler than the
midpoint rule. Compute the start like `getStartingPos` in parquet-mr, from the
first column chunk, so it matches `split_offsets` and does not depend on
`file_offset`; throw `INCORRECT_DATA` on invalid offsets instead of falling
back to 0.

PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Replace the midpoint-based assignment in `splitByByteRanges` with the same
greedy accumulation as `splitToBuckets`: a row group joins the current bucket
while the bucket stays within `cluster_table_function_buckets_batch_size`.

PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +308 to +314
if (protocol_version >= DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION_WITH_FILE_BUCKET_BYTE_RANGE)
{
writeVarUInt(byte_range.has_value() ? 1 : 0, buffer);
if (byte_range.has_value())
{
writeVarUInt(byte_range->first, buffer);
writeVarUInt(byte_range->second, buffer);

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.

⚠️ Major — document the new native-protocol encoding.

Connection::sendClusterFunctionReadTaskResponse sends this payload as a native ReadTaskResponse. Cluster protocol version 12 now appends a VarUInt presence flag and, when present, the byte offset and length. Even with cluster_table_function_split_by_split_offsets disabled, a version-12 Parquet bucket gains the zero presence flag, so this changes the wire layout independently of enabling the optimization.

Please update the matching native-protocol specification in this change to document version 12, the gated fields and their ordering, and the restriction on older workers. The English specification currently lives at docs/resources/develop-contribute/native-protocol/protocol.mdx; no protocol documentation is included in this diff.

scanhex12 and others added 2 commits November 2, 2026 12:28
…t-by-split-offsets

Keep writing `split_offsets` from `master`, which an earlier revert in this branch would have dropped.
Move `DBMS_CLUSTER_PROCESSING_PROTOCOL_VERSION_WITH_FILE_BUCKET_BYTE_RANGE` to 14 after the versions taken in `master`.
Select the row groups of a byte range in `Reader::selectRowGroups`, as column chunks are now parsed lazily.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@arsenmuk arsenmuk self-assigned this Nov 2, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing d9b99e265 with master a041790c2 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of b306e87de; 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.

Object file sizes

24 object files changed (+63.07 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Processors/Formats/Impl/ParquetV3BlockInputFormat.cpp.o 585.53 KiB 614.36 KiB +28.83 KiB (+4.92%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -293.6 s (-7%) in total before that adjustment.

Job report

@arsenmuk

arsenmuk commented Nov 3, 2026

Copy link
Copy Markdown
Member

we'd need to update docs/resources/develop-contribute/native-protocol/protocol.mdx after resolving the version conflict

scanhex12 and others added 5 commits November 3, 2026 20:17
- Make `count`-only reads of a Parquet bucket count only the selected row groups instead of the whole file.
- Do not read or write the per-file row count cache for bucket reads: a bucket count is not the file count.
- Let the last byte-range bucket extend to the end of the file, so a `file_size_in_bytes` smaller than the real size in the manifest does not lose the last row groups.
- Qualify the Spark `files` metadata table with the namespace in the test, and add a standalone `SELECT count()` assertion.

#125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-by-split-offsets

# Conflicts:
#	src/Core/ProtocolDefines.h
… test

Iceberg returns `split_offsets` of a data file only if the last offset is
below the size of the file, so a query of the `files` metadata table that
does not project `file_size_in_bytes` reads them as `NULL`, with Spark 4.0
and Iceberg 1.11.0 of the integration test image. The test selected only
`split_offsets`, so it failed on its own precondition before it reached
ClickHouse; `test_writes_split_offsets.py` selects both.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125636&sha=7174a395852497b4a7565b36c26cc1c082e91a2e&name_0=PR&name_1=Integration%20tests%20%28amd_asan_ubsan%2C%20db%20disk%2C%20targeted%29
PR: #125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A bucket selects either row group ids or a byte range, never both: byte range buckets are only made without a `QueryConditionCache` entry, and a worker does not consult the cache for a bucket it received. So `filterByMatchingRowGroups` goes back to building the bucket from row group ids, and throws on a byte range bucket.

#125636

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@arsenmuk arsenmuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm - still need to update protocol.mdx #125636 (comment)

@scanhex12
scanhex12 enabled auto-merge November 4, 2026 14:58
@scanhex12
scanhex12 added this pull request to the merge queue Nov 4, 2026
Merged via the queue into master with commit 34b6eb9 Nov 4, 2026
185 checks passed
@scanhex12
scanhex12 deleted the iceberg-bucket-split-by-split-offsets branch November 4, 2026 18:00
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 4, 2026
scanhex12 added a commit that referenced this pull request Nov 4, 2026
…tting-improvements

Most of this branch landed through separate PRs:
#125611
#125615
#125636
Their versions are kept. Bucket splitting by `min_buckets` is applied on
top of the greedy splitter of master, the weight of a byte range bucket is
capped by the file size, byte ranges are gated by
`cluster_table_function_split_by_split_offsets`, and the duplicate test of
the filter pushdown is removed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Nov 4, 2026
…-parallel-read

Resolve conflicts with #125636 (`RowGroupSelection` as a `std::variant`, byte-range buckets):
`ReadManager::init` takes a `RowGroupSelection` together with `other_row_groups_are_read_by_other_readers`,
and `IBucketSplitter` has both `splitForParallelReading` and `splitByByteRanges`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 8, 2026
Version 16 sends the injection sites of every Iceberg identity partition
value, so the native protocol spec has to name it (.claude/CLAUDE.md
requires a spec update for a protocol version bump). Version 15 (the byte
range of a Parquet file bucket, ClickHouse#125636) was never added to the spec, so
it is documented here as well; the spec still said 14.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... and removed comp-datalake Data lake table formats (Iceberg/Delta/Hudi) integration. labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-iceberg Apache Iceberg tables: reading and writing Iceberg metadata (snapshots, manifests, schema evoluti... pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants