Coverage Report

Created: 2026-04-24 16:09

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