mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Allow values up to INT64_MAX for nth_value/lagInFrame/leadInFrame
This commit is contained in:
parent
62a29420bd
commit
b383115389
@ -423,7 +423,7 @@ void WindowTransform::advancePartitionEnd()
|
||||
assert(!partition_ended && partition_end == blocksEnd());
|
||||
}
|
||||
|
||||
auto WindowTransform::moveRowNumberNoCheck(const RowNumber & _x, int offset) const
|
||||
auto WindowTransform::moveRowNumberNoCheck(const RowNumber & _x, int64_t offset) const
|
||||
{
|
||||
RowNumber x = _x;
|
||||
|
||||
@ -461,9 +461,9 @@ auto WindowTransform::moveRowNumberNoCheck(const RowNumber & _x, int offset) con
|
||||
assertValid(x);
|
||||
assert(offset <= 0);
|
||||
|
||||
// abs(offset) is less than INT_MAX, as checked in the parser, so
|
||||
// abs(offset) is less than INT64_MAX, as checked in the parser, so
|
||||
// this negation should always work.
|
||||
assert(offset >= -INT_MAX);
|
||||
assert(offset >= -INT64_MAX);
|
||||
if (x.row >= static_cast<uint64_t>(-offset))
|
||||
{
|
||||
x.row -= -offset;
|
||||
@ -493,7 +493,7 @@ auto WindowTransform::moveRowNumberNoCheck(const RowNumber & _x, int offset) con
|
||||
return std::tuple{x, offset};
|
||||
}
|
||||
|
||||
auto WindowTransform::moveRowNumber(const RowNumber & _x, int offset) const
|
||||
auto WindowTransform::moveRowNumber(const RowNumber & _x, int64_t offset) const
|
||||
{
|
||||
auto [x, o] = moveRowNumberNoCheck(_x, offset);
|
||||
|
||||
@ -1620,11 +1620,11 @@ struct WindowFunctionLagLeadInFrame final : public WindowFunction
|
||||
"The offset for function {} must be nonnegative, {} given",
|
||||
getName(), offset);
|
||||
}
|
||||
if (offset > INT_MAX)
|
||||
if (offset > INT64_MAX)
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"The offset for function {} must be less than {}, {} given",
|
||||
getName(), INT_MAX, offset);
|
||||
getName(), INT64_MAX, offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1698,11 +1698,11 @@ struct WindowFunctionNthValue final : public WindowFunction
|
||||
workspace.argument_column_indices[1]])[
|
||||
transform->current_row.row].get<Int64>();
|
||||
|
||||
if (offset > INT_MAX || offset <= 0)
|
||||
if (offset > INT64_MAX || offset <= 0)
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"The offset for function {} must be in (0, {}], {} given",
|
||||
getName(), INT_MAX, offset);
|
||||
getName(), INT64_MAX, offset);
|
||||
}
|
||||
|
||||
--offset;
|
||||
|
@ -218,8 +218,8 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
auto moveRowNumber(const RowNumber & _x, int offset) const;
|
||||
auto moveRowNumberNoCheck(const RowNumber & _x, int offset) const;
|
||||
auto moveRowNumber(const RowNumber & _x, int64_t offset) const;
|
||||
auto moveRowNumberNoCheck(const RowNumber & _x, int64_t offset) const;
|
||||
|
||||
void assertValid(const RowNumber & x) const
|
||||
{
|
||||
|
@ -1150,13 +1150,31 @@ WINDOW w AS (ORDER BY number ASC)
|
||||
2 0 2
|
||||
3 0 2
|
||||
4 0 2
|
||||
-- UBsan
|
||||
SELECT nth_value(number, -9223372036854775808) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, 0) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, /* INT_MAX+1 */ 2147483648) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, /* INT_MAX */ 2147483647) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC);
|
||||
-- nth_value UBsan
|
||||
SELECT nth_value(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, 0) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
0
|
||||
SELECT nth_value(number, 1) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC);
|
||||
SELECT nth_value(1, 1) OVER ();
|
||||
1
|
||||
-- lagInFrame UBsan
|
||||
SELECT lagInFrame(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT lagInFrame(1, 0) OVER ();
|
||||
1
|
||||
SELECT lagInFrame(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT lagInFrame(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
0
|
||||
SELECT lagInFrame(1, 1) OVER ();
|
||||
0
|
||||
-- leadInFrame UBsan
|
||||
SELECT leadInFrame(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT leadInFrame(1, 0) OVER ();
|
||||
1
|
||||
SELECT leadInFrame(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT leadInFrame(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
0
|
||||
SELECT leadInFrame(1, 1) OVER ();
|
||||
0
|
||||
-- In this case, we had a problem with PartialSortingTransform returning zero-row
|
||||
-- chunks for input chunks w/o columns.
|
||||
|
@ -435,12 +435,26 @@ FROM numbers(5)
|
||||
WINDOW w AS (ORDER BY number ASC)
|
||||
;
|
||||
|
||||
-- UBsan
|
||||
SELECT nth_value(number, -9223372036854775808) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, 0) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, /* INT_MAX+1 */ 2147483648) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(number, /* INT_MAX */ 2147483647) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC);
|
||||
SELECT nth_value(number, 1) OVER w AS v FROM numbers(1) WINDOW w AS (ORDER BY number DESC);
|
||||
-- nth_value UBsan
|
||||
SELECT nth_value(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, 0) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT nth_value(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
SELECT nth_value(1, 1) OVER ();
|
||||
|
||||
-- lagInFrame UBsan
|
||||
SELECT lagInFrame(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT lagInFrame(1, 0) OVER ();
|
||||
SELECT lagInFrame(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT lagInFrame(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
SELECT lagInFrame(1, 1) OVER ();
|
||||
|
||||
-- leadInFrame UBsan
|
||||
SELECT leadInFrame(1, -1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT leadInFrame(1, 0) OVER ();
|
||||
SELECT leadInFrame(1, /* INT64_MAX+1 */ 0x7fffffffffffffff+1) OVER (); -- { serverError BAD_ARGUMENTS }
|
||||
SELECT leadInFrame(1, /* INT64_MAX */ 0x7fffffffffffffff) OVER ();
|
||||
SELECT leadInFrame(1, 1) OVER ();
|
||||
|
||||
-- In this case, we had a problem with PartialSortingTransform returning zero-row
|
||||
-- chunks for input chunks w/o columns.
|
||||
|
Loading…
Reference in New Issue
Block a user