github-actions[bot] commented on code in PR #27787:
URL: https://github.com/apache/doris/pull/27787#discussion_r1414168816
##########
be/src/vec/functions/function_binary_arithmetic.h:
##########
@@ -364,121 +400,188 @@ struct DecimalBinaryOperation {
}
}
- static ColumnPtr adapt_decimal_constant_constant(A a, B b, DataTypePtr
res_data_type) {
+public:
+ static ColumnPtr adapt_decimal_constant_constant(A a, B b, const
ResultType& max_result_number,
+ const ResultType&
scale_diff_multiplier,
+ DataTypePtr
res_data_type) {
auto column_result = ColumnDecimal<ResultType>::create(
1, assert_cast<const
DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
- if constexpr (return_nullable_type && !is_to_null_type &&
+ if constexpr (check_overflow && !is_to_null_type &&
((!OpTraits::is_multiply && !OpTraits::is_plus_minus) ||
IsDecimalV2<A> ||
IsDecimalV2<B>)) {
LOG(FATAL) << "Invalid function type!";
return column_result;
- } else if constexpr (return_nullable_type || is_to_null_type) {
+ } else if constexpr (is_to_null_type) {
auto null_map = ColumnUInt8::create(1, 0);
column_result->get_element(0) = constant_constant(a, b,
null_map->get_element(0));
return ColumnNullable::create(std::move(column_result),
std::move(null_map));
} else {
- column_result->get_element(0) = constant_constant(a, b);
+ column_result->get_element(0) =
+ constant_constant(a, b, max_result_number,
scale_diff_multiplier);
return column_result;
}
}
static ColumnPtr adapt_decimal_vector_constant(ColumnPtr column_left, B b,
+ const ResultType&
max_result_number,
+ const ResultType&
scale_diff_multiplier,
DataTypePtr res_data_type) {
auto column_left_ptr = check_and_get_column<typename
Traits::ColumnVectorA>(column_left);
auto column_result = ColumnDecimal<ResultType>::create(
column_left->size(),
assert_cast<const
DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
DCHECK(column_left_ptr != nullptr);
- if constexpr (return_nullable_type && !is_to_null_type &&
+ if constexpr (check_overflow && !is_to_null_type &&
((!OpTraits::is_multiply && !OpTraits::is_plus_minus) ||
IsDecimalV2<A> ||
IsDecimalV2<B>)) {
LOG(FATAL) << "Invalid function type!";
return column_result;
- } else if constexpr (return_nullable_type || is_to_null_type) {
+ } else if constexpr (is_to_null_type) {
auto null_map = ColumnUInt8::create(column_left->size(), 0);
vector_constant(column_left_ptr->get_data().data(), b,
column_result->get_data().data(),
null_map->get_data(), column_left->size());
return ColumnNullable::create(std::move(column_result),
std::move(null_map));
} else {
vector_constant(column_left_ptr->get_data().data(), b,
column_result->get_data().data(),
- column_left->size());
+ column_left->size(), max_result_number,
scale_diff_multiplier);
return column_result;
}
}
static ColumnPtr adapt_decimal_constant_vector(A a, ColumnPtr column_right,
+ const ResultType&
max_result_number,
+ const ResultType&
scale_diff_multiplier,
DataTypePtr res_data_type) {
auto column_right_ptr = check_and_get_column<typename
Traits::ColumnVectorB>(column_right);
auto column_result = ColumnDecimal<ResultType>::create(
column_right->size(),
assert_cast<const
DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
DCHECK(column_right_ptr != nullptr);
- if constexpr (return_nullable_type && !is_to_null_type &&
+ if constexpr (check_overflow && !is_to_null_type &&
((!OpTraits::is_multiply && !OpTraits::is_plus_minus) ||
IsDecimalV2<A> ||
IsDecimalV2<B>)) {
LOG(FATAL) << "Invalid function type!";
return column_result;
- } else if constexpr (return_nullable_type || is_to_null_type) {
+ } else if constexpr (is_to_null_type) {
auto null_map = ColumnUInt8::create(column_right->size(), 0);
constant_vector(a, column_right_ptr->get_data().data(),
column_result->get_data().data(),
null_map->get_data(),
column_right->size());
return ColumnNullable::create(std::move(column_result),
std::move(null_map));
} else {
constant_vector(a, column_right_ptr->get_data().data(),
- column_result->get_data().data(),
column_right->size());
+ column_result->get_data().data(),
column_right->size(),
+ max_result_number, scale_diff_multiplier);
return column_result;
}
}
static ColumnPtr adapt_decimal_vector_vector(ColumnPtr column_left,
ColumnPtr column_right,
+ const ResultType&
max_result_number,
+ const ResultType&
scale_diff_multiplier,
DataTypePtr res_data_type) {
auto column_left_ptr = check_and_get_column<typename
Traits::ColumnVectorA>(column_left);
auto column_right_ptr = check_and_get_column<typename
Traits::ColumnVectorB>(column_right);
- auto column_result = ColumnDecimal<ResultType>::create(
- column_left->size(),
- assert_cast<const
DataTypeDecimal<ResultType>&>(*res_data_type).get_scale());
+ const auto& type_result = assert_cast<const
DataTypeDecimal<ResultType>&>(*res_data_type);
+ auto column_result =
+ ColumnDecimal<ResultType>::create(column_left->size(),
type_result.get_scale());
DCHECK(column_left_ptr != nullptr && column_right_ptr != nullptr);
- if constexpr (return_nullable_type && !is_to_null_type &&
+ if constexpr (check_overflow && !is_to_null_type &&
((!OpTraits::is_multiply && !OpTraits::is_plus_minus) ||
IsDecimalV2<A> ||
IsDecimalV2<B>)) {
LOG(FATAL) << "Invalid function type!";
return column_result;
- } else if constexpr (return_nullable_type || is_to_null_type) {
+ } else if constexpr (is_to_null_type) {
auto null_map = ColumnUInt8::create(column_result->size(), 0);
vector_vector(column_left_ptr->get_data().data(),
column_right_ptr->get_data().data(),
column_result->get_data().data(),
null_map->get_data(),
column_left->size());
return ColumnNullable::create(std::move(column_result),
std::move(null_map));
} else {
vector_vector(column_left_ptr->get_data().data(),
column_right_ptr->get_data().data(),
- column_result->get_data().data(),
column_left->size());
+ column_result->get_data().data(),
column_left->size(), max_result_number,
+ scale_diff_multiplier);
return column_result;
}
}
private:
/// 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,
Review Comment:
warning: function 'apply' has cognitive complexity of 61 (threshold 50)
[readability-function-cognitive-complexity]
```cpp
static ALWAYS_INLINE NativeResultType apply(NativeResultType a,
NativeResultType b,
^
```
<details>
<summary>Additional context</summary>
**be/src/vec/functions/function_binary_arithmetic.h:519:** +1, including
nesting penalty of 0, nesting level increased to 1
```cpp
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:519:** +1
```cpp
if constexpr (IsDecimalV2<B> || IsDecimalV2<A>) {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:523:** +1, nesting level
increased to 1
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:525:** +2, including
nesting penalty of 1, nesting level increased to 2
```cpp
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
```cpp
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
```cpp
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
```cpp
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
```cpp
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
```cpp
if (res256 > 0) {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:540:** +1, nesting level
increased to 6
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:546:** +5, including
nesting penalty of 4, nesting level increased to 5
```cpp
if (res256 > wide::Int256(max_result_number.value) ||
^
```
**be/src/vec/functions/function_binary_arithmetic.h:546:** +1
```cpp
if (res256 > wide::Int256(max_result_number.value) ||
^
```
**be/src/vec/functions/function_binary_arithmetic.h:550:** +1, nesting level
increased to 5
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:553:** +1, nesting level
increased to 4
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:557:** +1, nesting level
increased to 3
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:559:** +4, including
nesting penalty of 3, nesting level increased to 4
```cpp
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
```cpp
if (res >= 0) {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:563:** +1, nesting level
increased to 5
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:568:** +4, including
nesting penalty of 3, nesting level increased to 4
```cpp
if (res > max_result_number.value ||
^
```
**be/src/vec/functions/function_binary_arithmetic.h:568:** +1
```cpp
if (res > max_result_number.value ||
^
```
**be/src/vec/functions/function_binary_arithmetic.h:575:** +1, nesting level
increased to 2
```cpp
} else {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:577:** +3, including
nesting penalty of 2, nesting level increased to 3
```cpp
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
```cpp
if (res >= 0) {
^
```
**be/src/vec/functions/function_binary_arithmetic.h:580:** +1, nesting level
increased to 4
```cpp
} else {
^
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]