Coverage Report

Created: 2026-08-06 14:04

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