From f93d05c413965ed86278504d890398d393b57be6 Mon Sep 17 00:00:00 2001 From: PHILO-HE Date: Tue, 27 Feb 2024 22:41:34 +0800 Subject: [PATCH] Fix column case --- velox/exec/Window.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/velox/exec/Window.cpp b/velox/exec/Window.cpp index d918977e51b8..af3ff72f6f82 100644 --- a/velox/exec/Window.cpp +++ b/velox/exec/Window.cpp @@ -284,8 +284,13 @@ void updateKRowsOffsetsColumn( // moves ahead. int precedingFactor = isKPreceding ? -1 : 1; for (auto i = 0; i < numRows; i++) { - rawFrameBounds[i] = - (startRow + i) + vector_size_t(precedingFactor * offsets[i]); + auto startValue = (int64_t)(startRow + i) + precedingFactor * offsets[i]; + // Considers integer overflow case. + if (startValue != (int32_t)startValue) { + rawFrameBounds[i] = startValue < 0 ? 0 : numRows - 1; + } else { + rawFrameBounds[i] = startValue; + } } } @@ -301,12 +306,12 @@ void Window::updateKRowsFrameBounds( auto constantOffset = frameArg.constant.value(); auto startValue = (isKPreceding ? -constantOffset : constantOffset) + startRow; - // std::iota(rawFrameBounds, rawFrameBounds + numRows, startValue); for (int i = 0; i < numRows; i++) { + // Considers integer overflow case. if (startValue != (int32_t)startValue) { - *(rawFrameBounds + i) = startValue < 0 ? 0 : numRows - 1; + rawFrameBounds[i] = startValue < 0 ? 0 : numRows - 1; } else { - *(rawFrameBounds + i) = startValue; + rawFrameBounds[i] = startValue; } startValue = startValue + 1; }