Coverage Report

Created: 2026-08-03 18:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_percentile.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_percentile.h"
19
20
#include "core/types.h"
21
#include "exprs/aggregate/aggregate_function_simple_factory.h"
22
#include "exprs/aggregate/helpers.h"
23
24
namespace doris {
25
26
AggregateFunctionPtr create_aggregate_function_percentile_approx(
27
        const std::string& name, const DataTypes& argument_types, const DataTypePtr& result_type,
28
756
        const bool result_is_nullable, const AggregateFunctionAttr& attr) {
29
756
    const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
30
756
    if (argument_type->get_primitive_type() != PrimitiveType::TYPE_DOUBLE) {
31
0
        return nullptr;
32
0
    }
33
756
    if (argument_types.size() == 2) {
34
724
        return creator_without_type::create<AggregateFunctionPercentileApproxTwoParams>(
35
724
                argument_types, result_is_nullable, attr);
36
724
    }
37
37
    if (argument_types.size() == 3) {
38
37
        return creator_without_type::create<AggregateFunctionPercentileApproxThreeParams>(
39
37
                argument_types, result_is_nullable, attr);
40
37
    }
41
18.4E
    return nullptr;
42
32
}
43
44
AggregateFunctionPtr create_aggregate_function_percentile_approx_weighted(
45
        const std::string& name, const DataTypes& argument_types, const DataTypePtr& result_type,
46
60
        const bool result_is_nullable, const AggregateFunctionAttr& attr) {
47
60
    const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
48
60
    if (argument_type->get_primitive_type() != PrimitiveType::TYPE_DOUBLE) {
49
0
        return nullptr;
50
0
    }
51
60
    if (argument_types.size() == 3) {
52
39
        return creator_without_type::create<AggregateFunctionPercentileApproxWeightedThreeParams>(
53
39
                argument_types, result_is_nullable, attr);
54
39
    }
55
21
    if (argument_types.size() == 4) {
56
21
        return creator_without_type::create<AggregateFunctionPercentileApproxWeightedFourParams>(
57
21
                argument_types, result_is_nullable, attr);
58
21
    }
59
0
    return nullptr;
60
21
}
61
62
AggregateFunctionPtr create_aggregate_function_percentile_approx_array(
63
        const std::string& name, const DataTypes& argument_types, const DataTypePtr& result_type,
64
13
        const bool result_is_nullable, const AggregateFunctionAttr& attr) {
65
13
    const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
66
13
    if (argument_type->get_primitive_type() != PrimitiveType::TYPE_DOUBLE) {
67
0
        return nullptr;
68
0
    }
69
13
    if (argument_types.size() == 2) {
70
7
        return creator_without_type::create<AggregateFunctionPercentileApproxArray<false>>(
71
7
                argument_types, result_is_nullable, attr);
72
7
    }
73
6
    if (argument_types.size() == 3) {
74
6
        return creator_without_type::create<AggregateFunctionPercentileApproxArray<true>>(
75
6
                argument_types, result_is_nullable, attr);
76
6
    }
77
0
    return nullptr;
78
6
}
79
80
6
void register_aggregate_function_percentile(AggregateFunctionSimpleFactory& factory) {
81
6
    using creator = creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
82
6
                                           TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE>;
83
6
    factory.register_function_both("percentile", creator::creator<AggregateFunctionPercentile>);
84
6
    factory.register_function_both("percentile_array",
85
6
                                   creator::creator<AggregateFunctionPercentileArray>);
86
6
    factory.register_function_both("percentile_v2",
87
6
                                   creator::creator<AggregateFunctionPercentileV2>);
88
6
    factory.register_function_both("percentile_array_v2",
89
6
                                   creator::creator<AggregateFunctionPercentileArrayV2>);
90
6
    factory.register_alias("percentile", "percentile_cont");
91
6
}
92
93
5
void register_percentile_approx_old_function(AggregateFunctionSimpleFactory& factory) {
94
5
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_approx");
95
5
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_approx_weighted");
96
5
}
97
98
5
void register_aggregate_function_percentile_old(AggregateFunctionSimpleFactory& factory) {
99
5
    BeExecVersionManager::registe_restrict_function_compatibility("percentile");
100
5
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_array");
101
5
}
102
103
5
void register_aggregate_function_percentile_approx(AggregateFunctionSimpleFactory& factory) {
104
5
    factory.register_function_both("percentile_approx",
105
5
                                   create_aggregate_function_percentile_approx);
106
5
    factory.register_function_both("percentile_approx_array",
107
5
                                   create_aggregate_function_percentile_approx_array);
108
5
    factory.register_function_both("percentile_approx_weighted",
109
5
                                   create_aggregate_function_percentile_approx_weighted);
110
111
5
    register_percentile_approx_old_function(factory);
112
5
}
113
114
} // namespace doris