MCPcopy Create free account
hub / github.com/bytedance/bolt / getDistinctOutput

Method getDistinctOutput

bolt/exec/HashAggregation.cpp:652–720  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

650}
651
652RowVectorPtr HashAggregation::getDistinctOutput() {
653 BOLT_CHECK(isDistinct_);
654 BOLT_CHECK(!finished_);
655
656 if (newDistincts_) {
657 BOLT_CHECK_NOT_NULL(input_);
658
659 const auto& distinctNewGroups =
660 groupingSet_->hashLookup().distinctNewGroups;
661
662 // Accumulate results from all saved batches
663 const auto size = distinctNewGroups.size();
664 BufferPtr indices = allocateIndices(size, operatorCtx_->pool());
665 auto indicesPtr = indices->asMutable<vector_size_t>();
666
667 // Copy all batches into indices buffer
668 std::copy(distinctNewGroups.begin(), distinctNewGroups.end(), indicesPtr);
669
670 newDistincts_ = false;
671 auto output = fillOutput(size, indices);
672 numOutputRows_ += size;
673
674 recordRuntimeMetrics();
675
676 // Drop reference to input_ to make it singly-referenced at the producer and
677 // allow for memory reuse.
678 input_ = nullptr;
679
680 // Clear tracking after processing to prevent memory retention
681 groupingSet_->resetDistinctNewGroups();
682 resetPartialOutputIfNeed();
683 return output;
684 }
685 BOLT_CHECK(!newDistincts_);
686
687 auto outputGuard = folly::makeGuard([&]() { recordRuntimeMetrics(); });
688 if (!groupingSet_->hasSpilled()) {
689 if (noMoreInput_) {
690 finished_ = true;
691 if (auto numRows = groupingSet_->numDefaultGlobalGroupingSetRows()) {
692 prepareOutput(numRows.value(), false);
693 if (groupingSet_->getDefaultGlobalGroupingSetOutput(
694 resultIterator_, output_)) {
695 numOutputRows_ += output_->size();
696 return output_;
697 }
698 }
699 }
700 return nullptr;
701 }
702
703 if (!noMoreInput_) {
704 return nullptr;
705 }
706
707 const auto& queryConfig = operatorCtx_->driverCtx()->queryConfig();
708 const auto maxOutputRows = outputBatchRows(estimatedOutputRowSize_);
709 prepareOutput(maxOutputRows, false);

Callers

nothing calls this directly

Calls 14

allocateIndicesFunction · 0.85
copyFunction · 0.50
sizeMethod · 0.45
poolMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
hasSpilledMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected