-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[improvement](decimal) use new way for decimal arithmetic precision promotion #27787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[improvement](decimal) use new way for decimal arithmetic precision promotion #27787
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
be/src/common/exception.h
Outdated
| } while (0) | ||
|
|
||
| #define THROW_ARITHMETIC_OVERFLOW_ERRROR \ | ||
| throw Exception(ErrorCode::ARITHMETIC_OVERFLOW_ERRROR, "Arithmetic overflow") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this macro is not reasonable.
If we define such a macro, then we may need define many many macros... each error code need a macro
be/src/runtime/type_limit.h
Outdated
|
|
||
| template <typename T> | ||
| constexpr vectorized::UInt32 get_number_max_digits() { | ||
| if constexpr (std::is_same_v<T, vectorized::UInt8> || std::is_same_v<T, vectorized::Int8>) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add some comment
| if constexpr (narrow_integral) { | ||
| LOG(WARNING) << "multiply narrow scale, negative, narrow integral"; | ||
| if (UNLIKELY(converted_value.value < min_result.value)) { | ||
| THROW_ARITHMETIC_OVERFLOW_ERRROR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw exception is better than macro
ce957ef to
531a3b1
Compare
|
run buildall |
ccccbcb to
c691eaf
Compare
|
run buildall |
603533a to
a069f25
Compare
|
run buildall |
|
run pipelinex_p0 |
3eb6ea5 to
59a633e
Compare
|
run buildall |
1 similar comment
|
run buildall |
3608c81 to
0676754
Compare
be/src/common/exception.h
Outdated
| return Status::Error<false>(e.code(), e.to_string()); \ | ||
| } \ | ||
| } while (0) | ||
| } while (0) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty line
0676754 to
e01c532
Compare
|
run buildall |
|
(From new machine)TeamCity pipeline, clickbench performance test result: |
61c9d6a to
8c126c0
Compare
|
run buildall |
…tic precision promotion 1. [DNM](decimal) use new way for decimal arithmetic precision promotion 2. throw exception if it overflows for decimal arithmetics 3. throw exception if it overflows when casting among number types
55be2d3 to
4f14b9a
Compare
|
run buildall |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
| /// there's implicit type conversion here | ||
| static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b) { | ||
| template <bool need_adjust_scale> | ||
| static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'apply' has cognitive complexity of 61 (threshold 50) [readability-function-cognitive-complexity]
static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,
^Additional context
be/src/vec/functions/function_binary_arithmetic.h:519: +1, including nesting penalty of 0, nesting level increased to 1
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^be/src/vec/functions/function_binary_arithmetic.h:519: +1
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^be/src/vec/functions/function_binary_arithmetic.h:523: +1, nesting level increased to 1
} else {
^be/src/vec/functions/function_binary_arithmetic.h:525: +2, including nesting penalty of 1, nesting level increased to 2
if constexpr (OpTraits::can_overflow && check_overflow) {
^be/src/vec/functions/function_binary_arithmetic.h:527: +3, including nesting penalty of 2, nesting level increased to 3
if (UNLIKELY(Op::template apply<NativeResultType>(a, b, res))) {
^be/src/vec/functions/function_binary_arithmetic.h:528: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (OpTraits::is_plus_minus) {
^be/src/vec/functions/function_binary_arithmetic.h:533: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (std::is_same_v<NativeResultType, __int128>) {
^be/src/vec/functions/function_binary_arithmetic.h:535: +5, including nesting penalty of 4, nesting level increased to 5
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:536: +6, including nesting penalty of 5, nesting level increased to 6
if (res256 > 0) {
^be/src/vec/functions/function_binary_arithmetic.h:540: +1, nesting level increased to 6
} else {
^be/src/vec/functions/function_binary_arithmetic.h:546: +5, including nesting penalty of 4, nesting level increased to 5
if (res256 > wide::Int256(max_result_number.value) ||
^be/src/vec/functions/function_binary_arithmetic.h:546: +1
if (res256 > wide::Int256(max_result_number.value) ||
^be/src/vec/functions/function_binary_arithmetic.h:550: +1, nesting level increased to 5
} else {
^be/src/vec/functions/function_binary_arithmetic.h:553: +1, nesting level increased to 4
} else {
^be/src/vec/functions/function_binary_arithmetic.h:557: +1, nesting level increased to 3
} else {
^be/src/vec/functions/function_binary_arithmetic.h:559: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:560: +5, including nesting penalty of 4, nesting level increased to 5
if (res >= 0) {
^be/src/vec/functions/function_binary_arithmetic.h:563: +1, nesting level increased to 5
} else {
^be/src/vec/functions/function_binary_arithmetic.h:568: +4, including nesting penalty of 3, nesting level increased to 4
if (res > max_result_number.value ||
^be/src/vec/functions/function_binary_arithmetic.h:568: +1
if (res > max_result_number.value ||
^be/src/vec/functions/function_binary_arithmetic.h:575: +1, nesting level increased to 2
} else {
^be/src/vec/functions/function_binary_arithmetic.h:577: +3, including nesting penalty of 2, nesting level increased to 3
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:578: +4, including nesting penalty of 3, nesting level increased to 4
if (res >= 0) {
^be/src/vec/functions/function_binary_arithmetic.h:580: +1, nesting level increased to 4
} else {
^There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
| /// there's implicit type conversion here | ||
| static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b) { | ||
| template <bool need_adjust_scale> | ||
| static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'apply' has cognitive complexity of 61 (threshold 50) [readability-function-cognitive-complexity]
static ALWAYS_INLINE NativeResultType apply(NativeResultType a, NativeResultType b,
^Additional context
be/src/vec/functions/function_binary_arithmetic.h:519: +1, including nesting penalty of 0, nesting level increased to 1
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^be/src/vec/functions/function_binary_arithmetic.h:519: +1
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^be/src/vec/functions/function_binary_arithmetic.h:523: +1, nesting level increased to 1
} else {
^be/src/vec/functions/function_binary_arithmetic.h:525: +2, including nesting penalty of 1, nesting level increased to 2
if constexpr (OpTraits::can_overflow && check_overflow) {
^be/src/vec/functions/function_binary_arithmetic.h:527: +3, including nesting penalty of 2, nesting level increased to 3
if (UNLIKELY(Op::template apply<NativeResultType>(a, b, res))) {
^be/src/vec/functions/function_binary_arithmetic.h:528: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (OpTraits::is_plus_minus) {
^be/src/vec/functions/function_binary_arithmetic.h:533: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (std::is_same_v<NativeResultType, __int128>) {
^be/src/vec/functions/function_binary_arithmetic.h:535: +5, including nesting penalty of 4, nesting level increased to 5
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:536: +6, including nesting penalty of 5, nesting level increased to 6
if (res256 > 0) {
^be/src/vec/functions/function_binary_arithmetic.h:540: +1, nesting level increased to 6
} else {
^be/src/vec/functions/function_binary_arithmetic.h:546: +5, including nesting penalty of 4, nesting level increased to 5
if (res256 > wide::Int256(max_result_number.value) ||
^be/src/vec/functions/function_binary_arithmetic.h:546: +1
if (res256 > wide::Int256(max_result_number.value) ||
^be/src/vec/functions/function_binary_arithmetic.h:550: +1, nesting level increased to 5
} else {
^be/src/vec/functions/function_binary_arithmetic.h:553: +1, nesting level increased to 4
} else {
^be/src/vec/functions/function_binary_arithmetic.h:557: +1, nesting level increased to 3
} else {
^be/src/vec/functions/function_binary_arithmetic.h:559: +4, including nesting penalty of 3, nesting level increased to 4
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:560: +5, including nesting penalty of 4, nesting level increased to 5
if (res >= 0) {
^be/src/vec/functions/function_binary_arithmetic.h:563: +1, nesting level increased to 5
} else {
^be/src/vec/functions/function_binary_arithmetic.h:568: +4, including nesting penalty of 3, nesting level increased to 4
if (res > max_result_number.value || res < -max_result_number.value) {
^be/src/vec/functions/function_binary_arithmetic.h:568: +1
if (res > max_result_number.value || res < -max_result_number.value) {
^be/src/vec/functions/function_binary_arithmetic.h:574: +1, nesting level increased to 2
} else {
^be/src/vec/functions/function_binary_arithmetic.h:576: +3, including nesting penalty of 2, nesting level increased to 3
if constexpr (OpTraits::is_multiply && need_adjust_scale) {
^be/src/vec/functions/function_binary_arithmetic.h:577: +4, including nesting penalty of 3, nesting level increased to 4
if (res >= 0) {
^be/src/vec/functions/function_binary_arithmetic.h:579: +1, nesting level increased to 4
} else {
^|
run feut |
|
PR approved by at least one committer and no changes requested. |
|
PR approved by anyone and no changes requested. |
yiguolei
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…romotion (apache#27787) * [DNM](decimal) use new way for decimal arithmetic precision promotion * [improvement](decimal) [DNM](decimal) use new way for decimal arithmetic precision promotion 1. [DNM](decimal) use new way for decimal arithmetic precision promotion 2. throw exception if it overflows for decimal arithmetics 3. throw exception if it overflows when casting among number types * fix compile error of gcc * improvement --------- Co-authored-by: morrySnow <morrysnow@126.com>
Proposed changes
Issue Number: close #xxx
FE changes from #27492
decimalv3: use 38, min(decimalOverflowScale, ret_scale) as result precision if overflow
decimalv2 with largeint or bigint will promotion to decimalv3
decimalOverflowScale could be config by session variable
BE:
Further comments
If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...