Skip to content

Conversation

@jacktengg
Copy link
Contributor

@jacktengg jacktengg commented Nov 30, 2023

Proposed changes

Issue Number: close #xxx

FE changes from #27492

  1. decimalv3: use 38, min(decimalOverflowScale, ret_scale) as result precision if overflow

  2. decimalv2 with largeint or bigint will promotion to decimalv3

  3. decimalOverflowScale could be config by session variable

BE:

  1. throw exception if it overflows for decimal arithmetics
  2. throw exception if it overflows when casting among number types

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...

Copy link
Contributor

@github-actions github-actions bot left a 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

} while (0)

#define THROW_ARITHMETIC_OVERFLOW_ERRROR \
throw Exception(ErrorCode::ARITHMETIC_OVERFLOW_ERRROR, "Arithmetic overflow")
Copy link
Contributor

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


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>) {
Copy link
Contributor

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;
Copy link
Contributor

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

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch from ce957ef to 531a3b1 Compare November 30, 2023 16:05
@jacktengg
Copy link
Contributor Author

run buildall

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch 2 times, most recently from ccccbcb to c691eaf Compare December 1, 2023 01:35
@jacktengg jacktengg marked this pull request as ready for review December 1, 2023 01:35
@jacktengg
Copy link
Contributor Author

run buildall

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch 2 times, most recently from 603533a to a069f25 Compare December 3, 2023 15:17
@jacktengg
Copy link
Contributor Author

run buildall

@jacktengg
Copy link
Contributor Author

run pipelinex_p0

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch 2 times, most recently from 3eb6ea5 to 59a633e Compare December 4, 2023 01:26
@jacktengg
Copy link
Contributor Author

run buildall

1 similar comment
@jacktengg
Copy link
Contributor Author

run buildall

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch from 3608c81 to 0676754 Compare December 4, 2023 07:11
return Status::Error<false>(e.code(), e.to_string()); \
} \
} while (0)
} while (0) No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add an empty line

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch from 0676754 to e01c532 Compare December 4, 2023 07:12
@jacktengg
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

(From new machine)TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 43.95 seconds
stream load tsv: 560 seconds loaded 74807831229 Bytes, about 127 MB/s
stream load json: 18 seconds loaded 2358488459 Bytes, about 124 MB/s
stream load orc: 64 seconds loaded 1101869774 Bytes, about 16 MB/s
stream load parquet: 34 seconds loaded 861443392 Bytes, about 24 MB/s
insert into select: 29.2 seconds inserted 10000000 Rows, about 342K ops/s
storage size: 17163974810 Bytes

@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch 2 times, most recently from 61c9d6a to 8c126c0 Compare December 4, 2023 16:24
@jacktengg
Copy link
Contributor Author

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
@jacktengg jacktengg force-pushed the decimal_overflow_merge-rebase branch from 55be2d3 to 4f14b9a Compare December 4, 2023 16:29
@jacktengg
Copy link
Contributor Author

run buildall

Copy link
Contributor

@github-actions github-actions bot left a 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,
Copy link
Contributor

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 {
                      ^

Copy link
Contributor

@github-actions github-actions bot left a 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,
Copy link
Contributor

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 {
                      ^

@jacktengg
Copy link
Contributor Author

run feut

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Dec 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2023

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2023

PR approved by anyone and no changes requested.

Copy link
Contributor

@yiguolei yiguolei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yiguolei yiguolei merged commit 17016b9 into apache:master Dec 5, 2023
XuJianxu pushed a commit to XuJianxu/doris that referenced this pull request Dec 14, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. dev/2.0.4-merged kind/behavior-changed reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants