Function arrayDifference decimal math overflow

This commit is contained in:
Maksim Kita 2021-05-08 17:01:30 +03:00
parent c4be98566a
commit 108c2022d9
3 changed files with 19 additions and 1 deletions

View File

@ -13,6 +13,7 @@ namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int ILLEGAL_COLUMN;
extern const int DECIMAL_OVERFLOW;
}
/** arrayDifference() - returns an array with the difference between all pairs of neighboring elements.
@ -63,7 +64,23 @@ struct ArrayDifferenceImpl
else
{
Element curr = src[pos];
if constexpr (IsDecimalNumber<Element>)
{
using ResultNativeType = typename Result::NativeType;
ResultNativeType result_value;
bool overflow = common::subOverflow(static_cast<ResultNativeType>(curr.value), static_cast<ResultNativeType>(prev), result_value);
if (overflow)
throw Exception(ErrorCodes::DECIMAL_OVERFLOW, "Decimal math overflow");
dst[pos] = Result(result_value);
}
else
{
dst[pos] = curr - prev;
}
prev = curr;
}
}

View File

@ -0,0 +1 @@
SELECT arrayDifference([toDecimal32(100.0000991821289, 0), -2147483647]) AS x; --{serverError 407}