mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 15:12:02 +00:00
Function arrayDifference decimal math overflow
This commit is contained in:
parent
c4be98566a
commit
108c2022d9
@ -13,6 +13,7 @@ namespace ErrorCodes
|
|||||||
{
|
{
|
||||||
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
||||||
extern const int ILLEGAL_COLUMN;
|
extern const int ILLEGAL_COLUMN;
|
||||||
|
extern const int DECIMAL_OVERFLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** arrayDifference() - returns an array with the difference between all pairs of neighboring elements.
|
/** arrayDifference() - returns an array with the difference between all pairs of neighboring elements.
|
||||||
@ -63,7 +64,23 @@ struct ArrayDifferenceImpl
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
Element curr = src[pos];
|
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;
|
dst[pos] = curr - prev;
|
||||||
|
}
|
||||||
|
|
||||||
prev = curr;
|
prev = curr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
SELECT arrayDifference([toDecimal32(100.0000991821289, 0), -2147483647]) AS x; --{serverError 407}
|
Loading…
Reference in New Issue
Block a user