diff --git a/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp b/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp index 06d259f088bcc..65d5cc0bf6e50 100644 --- a/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp +++ b/velox/functions/prestosql/window/tests/AggregateWindowTest.cpp @@ -202,13 +202,73 @@ TEST_F(AggregateWindowTest, testDecimal) { TEST_F(AggregateWindowTest, integerOverflowRowsFrame) { auto c0 = makeFlatVector({-1, -1, -1, -1, -1, -1, 2, 2, 2, 2}); auto c1 = makeFlatVector({-1, -2, -3, -4, -5, -6, -7, -8, -9, -10}); - auto input = makeRowVector({c0, c1}); + // INT32_MAX: 2147483647 + auto c2 = makeFlatVector( + {1, + 2147483647, + 2147483646, + 2147483645, + 1, + 10, + 1, + 2147483647, + 2147483646, + 2147483645}); + auto c3 = makeFlatVector( + {2147483651, + 2147483650, + 2147483649, + 2147483648, + 2147483647, + 21474836, + 2147483650, + 2147483650, + 2147483649, + 2147483648}); + auto input = makeRowVector({c0, c1, c2, c3}); - auto expected = makeRowVector( - {c0, c1, makeFlatVector({6, 5, 4, 3, 2, 1, 4, 3, 2, 1})}); std::string overClause = "partition by c0 order by c1 desc"; - // Use max value of int32_t. - std::string frameClause = "rows between 0 preceding and 2147483647 following"; + // Test with literal larger than INT32_MAX (2147483647). + std::string frameClause = "rows between 0 preceding and 2147483650 following"; + auto expected = makeRowVector( + {c0, + c1, + c2, + c3, + makeFlatVector({6, 5, 4, 3, 2, 1, 4, 3, 2, 1})}); + WindowTestBase::testWindowFunction( + {input}, "count(c1)", overClause, frameClause, expected); + + // Test integer overflow with column-specified following (int32). + frameClause = "rows between 0 preceding and c2 following"; + expected = makeRowVector( + {c0, + c1, + c2, + c3, + makeFlatVector({2, 5, 4, 3, 2, 1, 2, 3, 2, 1})}); + WindowTestBase::testWindowFunction( + {input}, "count(c1)", overClause, frameClause, expected); + + // Test integer overflow with column-specified following (int64). + frameClause = "rows between 0 preceding and c3 following"; + expected = makeRowVector( + {c0, + c1, + c2, + c3, + makeFlatVector({6, 5, 4, 3, 2, 1, 4, 3, 2, 1})}); + WindowTestBase::testWindowFunction( + {input}, "count(c1)", overClause, frameClause, expected); + + // Test integer overflow with column-specified preceding (int64). + frameClause = "rows between c3 preceding and 0 following"; + expected = makeRowVector( + {c0, + c1, + c2, + c3, + makeFlatVector({1, 2, 3, 4, 5, 6, 1, 2, 3, 4})}); WindowTestBase::testWindowFunction( {input}, "count(c1)", overClause, frameClause, expected); }