| 915 | } |
| 916 | |
| 917 | RowVectorPtr Window::getOutput() { |
| 918 | MicrosecondTimer timer(&computeWindowFunctionTimeUs_); |
| 919 | if (needSort_ && !noMoreInput_) { |
| 920 | return nullptr; |
| 921 | } |
| 922 | if (isFinished()) { |
| 923 | recordWindowStats(); |
| 924 | if (numRows_ == 0 || numRows_ - numProcessedRows_ == 0) { |
| 925 | windowBuild_->finish(); |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | if (numRows_ == 0) { |
| 930 | return nullptr; |
| 931 | } |
| 932 | |
| 933 | auto numRowsLeft = numRows_ - numProcessedRows_; |
| 934 | if (numRowsLeft == 0) { |
| 935 | return nullptr; |
| 936 | } |
| 937 | |
| 938 | if (!currentPartition_) { |
| 939 | callResetPartition(); |
| 940 | if (!currentPartition_) { |
| 941 | // WindowBuild doesn't have a partition to output. |
| 942 | if (isFinished()) { |
| 943 | windowBuild_->finish(); |
| 944 | } |
| 945 | return nullptr; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | if (isSpillableWindowBuild_ && currentPartition_->isSpilled()) { |
| 950 | return getOutputFromSpilledPartition(); |
| 951 | } |
| 952 | |
| 953 | if (currentPartition_->supportRowsStreaming() && |
| 954 | partitionOffset_ == currentPartition_->numRows()) { |
| 955 | if (!currentPartition_->buildNextRows()) { |
| 956 | windowBuild_->loadNextPartialPartitionFromSpill(); |
| 957 | return nullptr; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | auto numOutputRows = std::min(numRowsPerOutput_, numRowsLeft); |
| 962 | auto usedBytes = operatorCtx_->pool()->currentBytes(); |
| 963 | auto result = BaseVector::create<RowVector>( |
| 964 | outputType_, numOutputRows, operatorCtx_->pool()); |
| 965 | |
| 966 | // Compute the output values of window functions. |
| 967 | auto numResultRows = callApplyLoop(numOutputRows, result); |
| 968 | if (numRows_ == 0 || numRows_ - numProcessedRows_ == 0) { |
| 969 | windowBuild_->finish(); |
| 970 | } |
| 971 | |
| 972 | auto resultBytes = operatorCtx_->pool()->currentBytes() - usedBytes; |
| 973 | std::optional<uint64_t> resultRowSize = resultBytes / numResultRows; |
| 974 |
nothing calls this directly
no test coverage detected