From d75d2c119e0854eea163adea3dde7799dcf33a1d Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Tue, 10 Dec 2024 01:15:59 +0800 Subject: [PATCH] Detect pattern --- velox/exec/WindowPartition.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/velox/exec/WindowPartition.cpp b/velox/exec/WindowPartition.cpp index 6f06dd713a6ff..2c75661c75d08 100644 --- a/velox/exec/WindowPartition.cpp +++ b/velox/exec/WindowPartition.cpp @@ -365,7 +365,8 @@ void WindowPartition::updateKRangeFrameBounds( vector_size_t start = 0; vector_size_t end; - vector_size_t lastFoundIndex = isPreceding ? 0 : -1; + // vector_size_t lastFoundIndex = isPreceding ? 0 : -1; + vector_size_t lastFoundIndex = 0; // frameColumn is a column index into the original input rows, while // orderByColumn and mappedFrameColumn are column indices into rows in data_ // after the columns are reordered as per inputMapping_. @@ -413,12 +414,30 @@ void WindowPartition::updateKRangeFrameBounds( // [0, currentRow] are examined. For following bounds, rows between // [currentRow, numRows()) are checked. if (isPreceding) { - start = - lastFoundIndex == -1 ? 0 : std::min(lastFoundIndex, numRows - 1); + // start = + // lastFoundIndex == -1 ? 0 : std::min(lastFoundIndex, numRows - 1); + if (i == 0) { + start = 0; + } else { + auto compareResult = data_->compare( + partition_[currentRow - 1], + partition_[currentRow], + mappedFrameColumn, + mappedFrameColumn, + flags); + if (compareResult <= 0) { + start = lastFoundIndex == -1 + ? 0 + : std::min(lastFoundIndex, numRows - 1); + } else { + start = 0; + } + } end = currentRow + 1; } else { - start = lastFoundIndex == -1 ? currentRow - : std::min(lastFoundIndex, numRows - 1); + // start = lastFoundIndex == -1 ? currentRow + // : std::min(lastFoundIndex, numRows - 1); + start = currentRow; end = partition_.size(); } rawFrameBounds[i] = searchFrameValue(