| 542 | } |
| 543 | |
| 544 | RowVectorPtr HashAggregation::getOutput() { |
| 545 | if (BOLT_TEST_VALUE_ENABLED()) { |
| 546 | bool injectSegfault = false; |
| 547 | BOLT_TEST_ADJUST( |
| 548 | "bytedance::bolt::exec::HashAggregation::getOutput", &injectSegfault); |
| 549 | if (injectSegfault) { |
| 550 | triggerSegfault(); |
| 551 | } |
| 552 | } |
| 553 | if (finished_) { |
| 554 | input_ = nullptr; |
| 555 | return nullptr; |
| 556 | } |
| 557 | if (abandonedPartialAggregation_) { |
| 558 | if (noMoreInput_) { |
| 559 | finished_ = true; |
| 560 | } |
| 561 | if (!input_) { |
| 562 | return nullptr; |
| 563 | } |
| 564 | prepareOutput(input_->size(), false); |
| 565 | groupingSet_->toIntermediate(input_, output_); |
| 566 | numOutputRows_ += input_->size(); |
| 567 | input_ = nullptr; |
| 568 | return output_; |
| 569 | } |
| 570 | |
| 571 | // Produce results if one of the following is true: |
| 572 | // - received no-more-input message; |
| 573 | // - partial aggregation reached memory limit; |
| 574 | // - distinct aggregation has new keys; |
| 575 | // - running in partial streaming mode and have some output ready. |
| 576 | if (!noMoreInput_ && !partialFull_ && !newDistincts_ && |
| 577 | !groupingSet_->hasOutput()) { |
| 578 | input_ = nullptr; |
| 579 | return nullptr; |
| 580 | } |
| 581 | |
| 582 | if (isDistinct_) { |
| 583 | auto currentOutput = getDistinctOutput(); |
| 584 | // Accumulate the generated output using append() |
| 585 | if (currentOutput) { |
| 586 | if (!accumulatedOutput_) { |
| 587 | if (currentOutput->size() >= minOutputRows_) { |
| 588 | return currentOutput; |
| 589 | } |
| 590 | accumulatedOutput_ = |
| 591 | RowVector::createEmpty(currentOutput->type(), operatorCtx_->pool()); |
| 592 | } |
| 593 | accumulatedOutput_->append(currentOutput.get()); |
| 594 | } |
| 595 | |
| 596 | // Handle accumulated output when no more input or memory pressure |
| 597 | if (accumulatedOutput_ && |
| 598 | (finished_ || partialFull_ || |
| 599 | accumulatedOutput_->size() >= minOutputRows_ || |
| 600 | abandonedPartialAggregation_)) { |
| 601 | auto result = std::move(accumulatedOutput_); |
no test coverage detected