| 59 | |
| 60 | template <RowFormat R> |
| 61 | bool RowsStreamingWindowPartition<R>::buildNextRows() { |
| 62 | if (currentPartition_ >= int(partitionStartRows_.size() - 2) || |
| 63 | !getPartialPartitionFinished()) |
| 64 | return false; |
| 65 | |
| 66 | currentPartition_++; |
| 67 | |
| 68 | // Erase previous rows in current partition. |
| 69 | if (currentPartition_ > 0) { |
| 70 | auto numPreviousPartitionRows = partitionStartRows_[currentPartition_] - |
| 71 | partitionStartRows_[currentPartition_ - 1]; |
| 72 | if constexpr (R == RowFormat::kSerializedRows) { |
| 73 | for (auto i = bufferStarts_[currentPartition_ - 1]; |
| 74 | i < bufferStarts_[currentPartition_]; |
| 75 | i++) { |
| 76 | if (allocatedSizes_[i] > 0) { |
| 77 | this->data_->pool()->free(allocatedStarts_[i], allocatedSizes_[i]); |
| 78 | allocatedSizes_[i] = 0; |
| 79 | } |
| 80 | } |
| 81 | } else { |
| 82 | BOLT_CHECK_EQ(R, RowFormat::kRowContainer); |
| 83 | this->data_->eraseRows( |
| 84 | folly::Range<char**>(sortedRows_.data(), numPreviousPartitionRows)); |
| 85 | } |
| 86 | sortedRows_.erase( |
| 87 | sortedRows_.begin(), sortedRows_.begin() + numPreviousPartitionRows); |
| 88 | } |
| 89 | |
| 90 | auto partitionSize = partitionStartRows_[currentPartition_ + 1] - |
| 91 | partitionStartRows_[currentPartition_]; |
| 92 | |
| 93 | this->partition_ = folly::Range(sortedRows_.data(), partitionSize); |
| 94 | return true; |
| 95 | } |
| 96 | |
| 97 | template <RowFormat R> |
| 98 | void RowsStreamingWindowPartition<R>::erasePartition() { |