diff --git a/velox/exec/RowsStreamingWindowBuild.cpp b/velox/exec/RowsStreamingWindowBuild.cpp index 8c72e0babf93..82b83da325db 100644 --- a/velox/exec/RowsStreamingWindowBuild.cpp +++ b/velox/exec/RowsStreamingWindowBuild.cpp @@ -102,6 +102,15 @@ void RowsStreamingWindowBuild::noMoreInput() { std::shared_ptr RowsStreamingWindowBuild::nextPartition() { VELOX_CHECK(hasNextPartition()); + + if (outputPartition_ > 0) { + windowPartitions_.erase( + windowPartitions_.begin(), windowPartitions_.begin() + 1); + windowPartitions_.shrink_to_fit(); + --outputPartition_; + --inputPartition_; + } + return windowPartitions_[++outputPartition_]; }