diff --git a/velox/exec/Window.cpp b/velox/exec/Window.cpp index e7296a2f2703..5872ee26ee99 100644 --- a/velox/exec/Window.cpp +++ b/velox/exec/Window.cpp @@ -312,9 +312,9 @@ void Window::updateKRowsFrameBounds( if (isKPreceding) { if (startValue < INT32_MIN) { - // Overflow happens for certain number of preceding rows. Moreover, - // considering partition size cannot be larger than INT32_MAX to produce - // positive value as upper bound, we directly use 0 for all rows. + // For overflow in kPreceding frames, k < INT32_MIN. Since the max + // number of rows in a partition is INT32_MAX, the frameBound will + // always be bound to the first row of the partition std::fill_n(rawFrameBounds, numRows, 0); return; } diff --git a/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp b/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp index 074d5d7e520d..a565cad0bc94 100644 --- a/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp +++ b/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp @@ -216,14 +216,14 @@ TEST_F(AggregateWindowTest, integerOverflowRowsFrame) { 2147483645}); auto c3 = makeFlatVector( {2147483651, + 1, 2147483650, - 2147483649, + 10, 2147483648, 2147483647, - 21474836, - 2147483650, + 2, + 2147483646, 2147483650, - 2147483649, 2147483648}); auto input = makeRowVector({c0, c1, c2, c3}); std::string overClause = "partition by c0 order by c1 desc"; @@ -268,7 +268,7 @@ TEST_F(AggregateWindowTest, integerOverflowRowsFrame) { c1, c2, c3, - makeFlatVector({6, 5, 4, 3, 2, 1, 4, 3, 2, 1})}); + makeFlatVector({6, 2, 4, 3, 2, 1, 3, 3, 2, 1})}); WindowTestBase::testWindowFunction( {input}, "count(c1)", overClause, frameClause, expected);