Skip to content

Commit

Permalink
Fix comment
Browse files Browse the repository at this point in the history
  • Loading branch information
PHILO-HE committed Mar 13, 2024
1 parent 66614b7 commit 1b998a2
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions velox/exec/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ void updateKRowsOffsetsColumn(
}
}

// Get the start index that integer overflow can happen for kFollowing.
FOLLY_ALWAYS_INLINE int32_t getOverflowStart(int64_t constantOffset) {
if (constantOffset > (int64_t)std::numeric_limits<int32_t>::max()) {
return 0;
} else {
return std::numeric_limits<int32_t>::max() - constantOffset + 1;
}
}

} // namespace

void Window::updateKRowsFrameBounds(
Expand All @@ -306,14 +315,28 @@ void Window::updateKRowsFrameBounds(
auto constantOffset = frameArg.constant.value();
auto startValue =
(isKPreceding ? -constantOffset : constantOffset) + startRow;
for (int i = 0; i < numRows; i++) {
// Considers integer overflow case.
if (startValue != (int32_t)startValue) {
rawFrameBounds[i] = startValue < 0 ? 0 : numRows - 1;

if (isKPreceding) {
// Considers a very large int64 constantOffset is used.
if (startValue < std::numeric_limits<int32_t>::min()) {
std::fill_n(rawFrameBounds, numRows, startRow);
} else {
// Integer overflow cannot happen.
std::iota(rawFrameBounds, rawFrameBounds + numRows, startValue);
}
} else {
auto overflowStart = getOverflowStart(constantOffset);
if (overflowStart >= 0 && overflowStart < numRows) {
std::iota(rawFrameBounds, rawFrameBounds + overflowStart, startValue);
// For remaining, set with the largest index for this partition.
std::fill_n(
rawFrameBounds + overflowStart,
numRows - overflowStart,
startRow + numRows - 1);
} else {
rawFrameBounds[i] = startValue;
// Integer overflow cannot happen.
std::iota(rawFrameBounds, rawFrameBounds + numRows, startValue);
}
startValue = startValue + 1;
}
} else {
currentPartition_->extractColumn(
Expand Down

0 comments on commit 1b998a2

Please sign in to comment.