diff --git a/velox/exec/WindowPartition.cpp b/velox/exec/WindowPartition.cpp index 2c75661c75d0..19f33812ed54 100644 --- a/velox/exec/WindowPartition.cpp +++ b/velox/exec/WindowPartition.cpp @@ -437,7 +437,21 @@ void WindowPartition::updateKRangeFrameBounds( } else { // start = lastFoundIndex == -1 ? currentRow // : std::min(lastFoundIndex, numRows - 1); - start = currentRow; + if (i == 0) { + start = currentRow; + } else { + auto compareResult = data_->compare( + partition_[currentRow - 1], + partition_[currentRow], + mappedFrameColumn, + mappedFrameColumn, + flags); + if (compareResult <= 0) { + start = lastFoundIndex == -1 ? currentRow : lastFoundIndex; + } else { + start = currentRow; + } + } end = partition_.size(); } rawFrameBounds[i] = searchFrameValue(