| 1732 | container, |
| 1733 | result, |
| 1734 | initGroupCount); |
| 1735 | outputUniqueGroups( |
| 1736 | uniqueRows, uniqueRes, uniqueCount, estimateUniqueBytesPerRow); |
| 1737 | |
| 1738 | if (initGroupCount) { |
| 1739 | extractSpillResult(result, true); |
| 1740 | } |
| 1741 | if (uniqueCount) { |
| 1742 | result->append(uniqueRes->wrappedVector()); |
| 1743 | stats_.aggOutputUniqueRows += uniqueCount; |
| 1744 | } |
| 1745 | return true; |
| 1746 | } |
| 1747 | } |
| 1748 | } |
| 1749 | } |
| 1750 | |
| 1751 | bool GroupingSet::mergeNextWithAggregates( |
| 1752 | int32_t maxOutputRows, |
| 1753 | int32_t maxOutputBytes, |
| 1754 | const RowVectorPtr& result) { |
| 1755 | // Merge all spill data, update aggregated intermediate result into groups, |
| 1756 | // and output the aggregated result. First, read the merged data and |
| 1757 | // temporarily store each row in a vector until the batch of a stream ends or |
| 1758 | // the number of rows reaches the limit. Then, copy all distinct keys to the |
| 1759 | // result and update the intermediate result to the groups until result size |
| 1760 | // reaches limit or all data processing is completed, finally extract result |
| 1761 | // in groups into result vector and return result. |
| 1762 | BOLT_CHECK_NOT_NULL(merge_); |
| 1763 | BOLT_CHECK(!isDistinct()); |
| 1764 | |
| 1765 | // True if 'merge_' indicates that the next key is the same as the current |
| 1766 | // one. |
| 1767 | bool nextKeyIsEqual{false}; |
| 1768 | |
| 1769 | // stores all rows need to be update to groups |
| 1770 | std::vector<const RowVector*> sources; |
| 1771 | std::vector<vector_size_t> sourceIndice; |
| 1772 | std::vector<char*> groupOfRows; |
| 1773 | |
| 1774 | // all distinct rows to extract keys |
| 1775 | std::vector<const RowVector*> distinctInputs; |
| 1776 | std::vector<vector_size_t> distinctIndices; |
| 1777 | std::vector<char*> groups; |
| 1778 | |
| 1779 | RowVectorPtr intermediate; |
| 1780 | uint64_t averageResultRowSize = 0; |
| 1781 | |
| 1782 | // gather all saved keys into result vector and all saved intermediate result |
| 1783 | // into intermediate and update into groups |
| 1784 | auto gatherAndUpdate = [&]() { |
| 1785 | NanosecondTimer aggTimer(&stats_.aggOutputUpdateTimeNs); |
| 1786 | if (!distinctInputs.empty()) { |
| 1787 | // copy keys to result |
| 1788 | auto oldResultSize = result->size(); |
| 1789 | result->resize(oldResultSize + distinctInputs.size()); |
| 1790 | for (auto i = 0; i < keyChannels_.size(); ++i) { |
| 1791 | gatherCopy( |
nothing calls this directly
no test coverage detected