Repository navigation
Replace Block to Chunk in Aggregator - #99228
Conversation
Replace name-based column resolution in `Aggregator` with precomputed positional data, removing the stored `Block header` member: - Remove `Aggregator::executeOnBlock(const Block &, ...)` overload - Remove `Aggregator::getHeader` — callers now use `Params::getHeader` directly - Precompute `keys_positions`, `aggregates_positions`, `key_types`, and `aggregate_state_types` in the constructor from the input header - Update `prepareOutputBlockColumns` and `finalizeBlock` to accept types directly instead of a `Block` header - Remove unused `rows` parameter from `finalizeBlock` - Move `header` storage to `AggregatingTransformParams` where it is still needed for output schema construction Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Change `mergeOnBlock` to accept `Columns`, `size_t rows`, `bool is_overflows` instead of `Block`, eliminating Block construction at call sites - Change `mergeStreamsImpl` and `mergeBlockWithoutKeyStreamsImpl` similarly - Move `makeRawKeyColumns` and `makeAggregateColumnsData` from `Params` methods to static functions in Aggregator.cpp, using positional column access instead of name-based lookups Co-Authored-By: Claude Opus 4.6 <[email protected]>
Introduce `Aggregator::AggregatedChunk` struct holding a `Chunk` with `bucket_num` and `is_overflows` metadata, avoiding `Block` and `BlockInfo` in the aggregation output path. - Add `AggregatedChunk` and `AggregatedChunks` types to Aggregator - Replace `convertToBlocks` with `convertToChunks` returning `AggregatedChunks` - Update callers in `TTLAggregationAlgorithm` and `MergingAggregatedTransform` to work with chunks, reconstructing `Block` only when needed for expression execution Co-Authored-By: Claude Opus 4.6 <[email protected]>
Replace `finalizeBlock` with `finalizeChunk` returning `Chunk` instead of `Block`. Eliminate `ConvertToBlockResVariant` by using `Chunks` (vector) as the uniform return type for `convertToBlockImpl`, `convertToBlockImplFinal`, and `convertToBlockImplNotFinal`. Replace `BlocksList` with `AggregatedChunks` in merge interfaces. Rename `prepareBlockAndFill*` methods to `prepareChunkAndFill*`. Update `recordAggregationKeySizes` to accept `Chunk` with positional key access. Replace `group_by_block` with `group_by_chunk` in `AggregatingInOrderTransform`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
29c0cc1 to
7899dab
Compare
|
Workflow [PR], commit [1b2e8bb] Summary: ✅ AI ReviewSummaryThis PR refactors aggregation internals to pass Missing context
ClickHouse Rules
Final Verdict
|
…tion order Two bugs introduced during Block-to-Chunk refactoring: 1. In the merge path (`only_merge`), `calculateKeysPositions` and `calculateAggregatesPositions` looked up argument names that don't exist in the merge header (which uses `column_name` instead). Fixed by returning empty when `only_merge` is set, and using `column_name` in `calculateAggregateStateTypes` for the merge path. 2. `Chunk::detachColumns` zeroes `num_rows` as a side effect, so `Chunk(cur_chunk.detachColumns(), cur_chunk.getNumRows())` passes 0 rows when `detachColumns` is evaluated first. Fixed by saving `num_rows` before detaching. Co-Authored-By: Claude Opus 4.6 <[email protected]>
| { | ||
| /// Only used in the execute path; in the merge path keys are accessed positionally. | ||
| if (params.only_merge) | ||
| return {}; |
There was a problem hiding this comment.
calculateKeysPositions returning an empty vector in only_merge mode breaks runtime statistics collection: recordAggregationKeySizes now relies on aggregator.getKeysPositions() to index key columns, so merge-path chunks report zero key bytes. This regresses RuntimeDataflowStatistics quality for merge pipelines. Please keep key positions available (e.g. 0..keys_size-1 in only_merge) or derive positional indices at the call site when recording key sizes.
…columns The merge path in `AggregatingTransform` was missing sparse column conversion after the Block-to-Chunk refactoring. On master, `materializeBlock` handled this; now `materializeChunk` is the Chunk analog — it converts const columns to full and removes sparse/replicated representations. Fixes exception "Column Sparse(UInt8) is not a contiguous block of memory" in `mergeStreamsImpl`. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Instead of returning an empty vector in `only_merge` mode, return sequential positions 0..keys_size-1. This keeps `getKeysPositions` usable for `recordAggregationKeySizes` in merge pipelines, preserving RuntimeDataflowStatistics quality. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…hunk After the Block-to-Chunk refactoring, `mergeBlocks` can return an empty `AggregatedChunk` (no columns). On master, `sortBlock` on an empty `Block` was a no-op, but the new code calls `header.cloneWithColumns(detachColumns())` which fails when the chunk has 0 columns but the header expects 3. Co-Authored-By: Claude Opus 4.6 <[email protected]>
| for (auto & chunk : chunks) | ||
| blocks.emplace_back(header.cloneWithColumns(chunk.detachColumns())); | ||
| agg_chunks.emplace_back(Aggregator::AggregatedChunk{std::move(chunk)}); |
There was a problem hiding this comment.
| agg_chunks.emplace_back(Aggregator::AggregatedChunk{std::move(chunk)}); | |
| agg_chunks.emplace_back(std::move(chunk)); |
it shouldn't be required, right?
| auto info = std::make_shared<AggregatedChunkInfo>(); | ||
| info->bucket_num = block.info.bucket_num; | ||
| info->is_overflows = block.info.is_overflows; | ||
| info->out_of_order_buckets = block.info.out_of_order_buckets; |
There was a problem hiding this comment.
Did we lose out_of_order_buckets?
| Block block = header.cloneWithColumns(cur_chunk.detachColumns()); | ||
| block.info.is_overflows = agg_info->is_overflows; | ||
| block.info.bucket_num = agg_info->bucket_num; | ||
| block.info.out_of_order_buckets = agg_info->out_of_order_buckets; |
There was a problem hiding this comment.
out_of_order_buckets disappeared again
C++20 parenthesized aggregate initialization allows `emplace_back` to construct `AggregatedChunk` directly from forwarded arguments, making the explicit type wrapper unnecessary. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…sume` Replace `addBlock(Block)` with `addChunk(Columns, size_t, Int32, bool)` to avoid constructing a `Block` from the incoming `Chunk` only to extract columns back later. The `Block` is now constructed inside `addChunk` only when needed for `ExpressionActions::execute` (grouping sets path). Co-Authored-By: Claude Opus 4.6 <[email protected]>
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 95.16% (786/826, 4 noise lines excluded) |
…ation (PR ClickHouse#99228) PR ClickHouse#99228 replaces `Block` with `Chunk` throughout the aggregation pipeline (17 files). Two correctness paths had no test coverage: 1. `04046`: ROLLUP and CUBE with external aggregation (`max_bytes_before_external_group_by = 1`) – exercises `writeToTemporaryFileImpl` and `GroupByModifierTransform::merge()`. Verifies results match for ROLLUP/CUBE with and without `group_by_use_nulls`. 2. `04047`: GROUPING SETS with external aggregation + `group_by_two_level_threshold = 1` – exercises `MergingAggregatedTransform::addChunk`, `mergeBlocks(BucketToChunks)`, and `convertBlockToTwoLevel`. Includes a single-set path to cover the reordering branch. Both tests pass, confirming the refactoring preserves correctness on these paths. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…-grouping-sets Add coverage tests for ROLLUP/CUBE/GROUPING SETS with external aggregation (PR #99228)
PR ClickHouse#99228 replaced `Block` with `Chunk` in the aggregation merge path but used `getColumns` (shared copy) instead of `detachColumns` (move). This keeps aggregate states alive across all buckets during parallel merge instead of freeing them incrementally, increasing memory pressure and concurrent arena operations. Restore immediate ownership transfer to match the old `std::move(block)` semantics. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Changelog category (leave one):
Documentation entry for user-facing changes
Version info
26.3.1.750