| 460 | } |
| 461 | |
| 462 | void GroupingSet::initializeGlobalAggregation() { |
| 463 | if (globalAggregationInitialized_) { |
| 464 | return; |
| 465 | } |
| 466 | |
| 467 | lookup_ = std::make_unique<HashLookup>(hashers_); |
| 468 | lookup_->reset(1); |
| 469 | |
| 470 | // Row layout is: |
| 471 | // - null flags - one bit per aggregate, |
| 472 | // - uint32_t row size, |
| 473 | // - fixed-width accumulators - one per aggregate |
| 474 | // |
| 475 | // Here we always make space for a row size since we only have one row and no |
| 476 | // RowContainer. The whole row is allocated to guarantee that alignment |
| 477 | // requirements of all aggregate functions are satisfied. |
| 478 | |
| 479 | // Allocate space for the null and initialized flags. |
| 480 | size_t numAggregates = aggregates_.size(); |
| 481 | if (sortedAggregations_) { |
| 482 | numAggregates++; |
| 483 | } |
| 484 | for (const auto& aggregation : distinctAggregations_) { |
| 485 | if (aggregation != nullptr) { |
| 486 | numAggregates++; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | int32_t rowSizeOffset = bits::nbytes(numAggregates); |
| 491 | int32_t offset = rowSizeOffset + sizeof(int32_t); |
| 492 | int32_t nullOffset = 0; |
| 493 | int32_t alignment = 1; |
| 494 | |
| 495 | for (auto& aggregate : aggregates_) { |
| 496 | auto& function = aggregate.function; |
| 497 | |
| 498 | Accumulator accumulator{ |
| 499 | aggregate.function.get(), aggregate.intermediateType}; |
| 500 | |
| 501 | // Accumulator offset must be aligned by their alignment size. |
| 502 | offset = bits::roundUp(offset, accumulator.alignment()); |
| 503 | |
| 504 | function->setAllocator(&stringAllocator_); |
| 505 | function->setOffsets( |
| 506 | offset, |
| 507 | RowContainer::nullByte(nullOffset), |
| 508 | RowContainer::nullMask(nullOffset), |
| 509 | rowSizeOffset); |
| 510 | |
| 511 | offset += accumulator.fixedWidthSize(); |
| 512 | ++nullOffset; |
| 513 | alignment = |
| 514 | RowContainer::combineAlignments(accumulator.alignment(), alignment); |
| 515 | } |
| 516 | |
| 517 | if (sortedAggregations_) { |
| 518 | auto accumulator = sortedAggregations_->accumulator(); |
| 519 |
nothing calls this directly
no test coverage detected