Coverage Report

Created: 2026-04-16 21:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_regr.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
18
#include "exprs/aggregate/aggregate_function_regr.h"
19
20
#include "core/data_type/data_type.h"
21
#include "core/data_type/define_primitive_type.h"
22
#include "exprs/aggregate/aggregate_function.h"
23
#include "exprs/aggregate/aggregate_function_simple_factory.h"
24
#include "exprs/aggregate/factory_helpers.h"
25
#include "exprs/aggregate/helpers.h"
26
27
namespace doris {
28
29
template <RegrFunctionKind kind>
30
AggregateFunctionPtr create_aggregate_function_regr(const std::string& name,
31
                                                    const DataTypes& argument_types,
32
                                                    const DataTypePtr& result_type,
33
                                                    const bool result_is_nullable,
34
0
                                                    const AggregateFunctionAttr& attr) {
35
0
    assert_arity_range(name, argument_types, 2, 2);
36
0
    DCHECK(argument_types[0]->get_primitive_type() == TYPE_DOUBLE);
37
0
    DCHECK(argument_types[1]->get_primitive_type() == TYPE_DOUBLE);
38
0
    if constexpr (kind == RegrFunctionKind::regr_count) {
39
0
        DCHECK(result_type->get_primitive_type() == TYPE_BIGINT);
40
0
        DCHECK(!result_is_nullable);
41
0
    } else {
42
0
        DCHECK(result_type->get_primitive_type() == TYPE_DOUBLE);
43
0
        DCHECK(result_is_nullable);
44
0
    }
45
46
0
    bool y_nullable_input = argument_types[0]->is_nullable();
47
0
    bool x_nullable_input = argument_types[1]->is_nullable();
48
0
    if (y_nullable_input) {
49
0
        if (x_nullable_input) {
50
0
            return creator_without_type::create_ignore_nullable<
51
0
                    AggregateFunctionRegr<TYPE_DOUBLE, kind, true, true>>(argument_types,
52
0
                                                                          result_is_nullable, attr);
53
0
        } else {
54
0
            return creator_without_type::create_ignore_nullable<
55
0
                    AggregateFunctionRegr<TYPE_DOUBLE, kind, true, false>>(
56
0
                    argument_types, result_is_nullable, attr);
57
0
        }
58
0
    } else {
59
0
        if (x_nullable_input) {
60
0
            return creator_without_type::create_ignore_nullable<
61
0
                    AggregateFunctionRegr<TYPE_DOUBLE, kind, false, true>>(
62
0
                    argument_types, result_is_nullable, attr);
63
0
        } else {
64
0
            return creator_without_type::create_ignore_nullable<
65
0
                    AggregateFunctionRegr<TYPE_DOUBLE, kind, false, false>>(
66
0
                    argument_types, result_is_nullable, attr);
67
0
        }
68
0
    }
69
0
}
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE0EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE1EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE2EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE3EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE4EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE5EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE6EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE7EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
Unexecuted instantiation: _ZN5doris30create_aggregate_function_regrILNS_16RegrFunctionKindE8EEESt10shared_ptrINS_18IAggregateFunctionEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIS2_IKNS_9IDataTypeEESaISG_EERKSG_bRKNS_21AggregateFunctionAttrE
70
71
1
void register_aggregate_function_regr(AggregateFunctionSimpleFactory& factory) {
72
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_avgx>::name,
73
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_avgx>);
74
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_avgy>::name,
75
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_avgy>);
76
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_count>::name,
77
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_count>);
78
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_slope>::name,
79
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_slope>);
80
1
    factory.register_function_both(
81
1
            RegrTraits<RegrFunctionKind::regr_intercept>::name,
82
1
            create_aggregate_function_regr<RegrFunctionKind::regr_intercept>);
83
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_sxx>::name,
84
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_sxx>);
85
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_syy>::name,
86
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_syy>);
87
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_sxy>::name,
88
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_sxy>);
89
1
    factory.register_function_both(RegrTraits<RegrFunctionKind::regr_r2>::name,
90
1
                                   create_aggregate_function_regr<RegrFunctionKind::regr_r2>);
91
1
}
92
93
} // namespace doris