Coverage Report

Created: 2026-08-18 12:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/plus.cpp
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/Plus.cpp
19
// and modified by Doris
20
21
#include "exprs/function/binary_arithmetic.h"
22
#include "exprs/function/simple_function_factory.h"
23
24
namespace doris {
25
template <PrimitiveType Type>
26
struct PlusImpl {
27
    static constexpr auto name = "add";
28
    static constexpr PrimitiveType PType = Type;
29
    using Arg = typename PrimitiveTypeTraits<Type>::CppType;
30
5.13M
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
Unexecuted instantiation: _ZN5doris8PlusImplILNS_13PrimitiveTypeE3EE5applyEaa
_ZN5doris8PlusImplILNS_13PrimitiveTypeE4EE5applyEss
Line
Count
Source
30
1.91k
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
_ZN5doris8PlusImplILNS_13PrimitiveTypeE5EE5applyEii
Line
Count
Source
30
4.68k
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
_ZN5doris8PlusImplILNS_13PrimitiveTypeE6EE5applyEll
Line
Count
Source
30
4.51M
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
_ZN5doris8PlusImplILNS_13PrimitiveTypeE7EE5applyEnn
Line
Count
Source
30
5.26k
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
_ZN5doris8PlusImplILNS_13PrimitiveTypeE9EE5applyEdd
Line
Count
Source
30
605k
    NO_SANITIZE_UNDEFINED static inline Arg apply(Arg a, Arg b) { return a + b; }
Unexecuted instantiation: _ZN5doris8PlusImplILNS_13PrimitiveTypeE8EE5applyEff
31
};
32
33
// FE casts both children of decimal add to exactly the same type as the return
34
// type (TypeCoercionUtils#processDecimalV3BinaryArithmetic), so only same-width
35
// pairs are reachable at runtime. Keep a single type parameter so mixed-width
36
// instantiations cannot be registered again.
37
template <PrimitiveType Type>
38
struct PlusDecimalImpl {
39
    static_assert(is_decimal(Type));
40
41
    constexpr static bool need_replace_null_data_to_default = true;
42
43
    static constexpr auto name = "add";
44
    static constexpr PrimitiveType PTypeA = Type;
45
    static constexpr PrimitiveType PTypeB = Type;
46
    using ArgNativeTypeA = typename PrimitiveTypeTraits<Type>::CppType::NativeType;
47
    using ArgNativeTypeB = typename PrimitiveTypeTraits<Type>::CppType::NativeType;
48
49
    template <PrimitiveType Result>
50
        requires(is_decimal(Result) && Result != TYPE_DECIMALV2)
51
    static inline typename PrimitiveTypeTraits<Result>::CppType::NativeType apply(
52
0
            ArgNativeTypeA a, ArgNativeTypeB b) {
53
0
        return static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(
54
0
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a) + b);
55
0
    }
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEii
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEii
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEii
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEii
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEll
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEll
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEll
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEll
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEnn
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEnn
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEnn
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEnn
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEN4wide7integerILm256EiEESA_
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEN4wide7integerILm256EiEESA_
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEN4wide7integerILm256EiEESA_
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEENS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeEN4wide7integerILm256EiEESA_
56
57
943
    static inline DecimalV2Value apply(const DecimalV2Value& a, const DecimalV2Value& b) {
58
943
        return DecimalV2Value(a.value() + b.value());
59
943
    }
60
61
    /// Apply operation and check overflow. It's used for Decimal operations. @returns true if overflowed, false otherwise.
62
    template <PrimitiveType Result>
63
        requires(is_decimal(Result) && Result != TYPE_DECIMALV2)
64
    NO_SANITIZE_UNDEFINED static inline bool apply(
65
            ArgNativeTypeA a, ArgNativeTypeB b,
66
2.33M
            typename PrimitiveTypeTraits<Result>::CppType::NativeType& c) {
67
2.33M
        return common::add_overflow(
68
2.33M
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a),
69
2.33M
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(b), c);
70
2.33M
    }
_ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbiiRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Line
Count
Source
66
436
            typename PrimitiveTypeTraits<Result>::CppType::NativeType& c) {
67
436
        return common::add_overflow(
68
436
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a),
69
436
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(b), c);
70
436
    }
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbiiRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbiiRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE28EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbiiRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbllRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
_ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbllRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Line
Count
Source
66
2.32M
            typename PrimitiveTypeTraits<Result>::CppType::NativeType& c) {
67
2.32M
        return common::add_overflow(
68
2.32M
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a),
69
2.32M
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(b), c);
70
2.32M
    }
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbllRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE29EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbllRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbnnRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbnnRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
_ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbnnRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Line
Count
Source
66
3.79k
            typename PrimitiveTypeTraits<Result>::CppType::NativeType& c) {
67
3.79k
        return common::add_overflow(
68
3.79k
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a),
69
3.79k
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(b), c);
70
3.79k
    }
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE30EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbnnRNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_28EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbN4wide7integerILm256EiEES6_RNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_29EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbN4wide7integerILm256EiEES6_RNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Unexecuted instantiation: _ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_30EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbN4wide7integerILm256EiEES6_RNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
_ZN5doris15PlusDecimalImplILNS_13PrimitiveTypeE35EE5applyILS1_35EQaaclL_ZNS_10is_decimalES1_ETL0__EneTL0__LS1_20EEEbN4wide7integerILm256EiEES6_RNS_19PrimitiveTypeTraitsIXT_EE7CppType10NativeTypeE
Line
Count
Source
66
86
            typename PrimitiveTypeTraits<Result>::CppType::NativeType& c) {
67
86
        return common::add_overflow(
68
86
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(a),
69
86
                static_cast<typename PrimitiveTypeTraits<Result>::CppType::NativeType>(b), c);
70
86
    }
71
};
72
73
8
void register_function_plus(SimpleFunctionFactory& factory) {
74
8
    factory.register_function<
75
8
            FunctionPlusMinus<PlusMinusDecimalImpl<PlusDecimalImpl<TYPE_DECIMALV2>>>>();
76
77
8
    factory.register_function<
78
8
            FunctionPlusMinus<PlusMinusDecimalImpl<PlusDecimalImpl<TYPE_DECIMAL32>>>>();
79
8
    factory.register_function<
80
8
            FunctionPlusMinus<PlusMinusDecimalImpl<PlusDecimalImpl<TYPE_DECIMAL64>>>>();
81
8
    factory.register_function<
82
8
            FunctionPlusMinus<PlusMinusDecimalImpl<PlusDecimalImpl<TYPE_DECIMAL128I>>>>();
83
8
    factory.register_function<
84
8
            FunctionPlusMinus<PlusMinusDecimalImpl<PlusDecimalImpl<TYPE_DECIMAL256>>>>();
85
86
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_TINYINT>>>>();
87
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_SMALLINT>>>>();
88
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_INT>>>>();
89
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_BIGINT>>>>();
90
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_LARGEINT>>>>();
91
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_DOUBLE>>>>();
92
8
    factory.register_function<FunctionPlusMinus<PlusMinusIntegralImpl<PlusImpl<TYPE_FLOAT>>>>();
93
8
}
94
} // namespace doris