Coverage Report

Created: 2026-04-27 08:40

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
775
        const bool result_is_nullable, const AggregateFunctionAttr& attr) {
29
775
    const DataTypePtr& argument_type = remove_nullable(argument_types[0]);
30
775
    if (argument_type->get_primitive_type() != PrimitiveType::TYPE_DOUBLE) {
31
0
        return nullptr;
32
0
    }
33
775
    if (argument_types.size() == 2) {
34
739
        return creator_without_type::create<AggregateFunctionPercentileApproxTwoParams>(
35
739
                argument_types, result_is_nullable, attr);
36
739
    }
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
36
}
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
7
void register_aggregate_function_percentile(AggregateFunctionSimpleFactory& factory) {
63
7
    using creator = creator_with_type_list<TYPE_TINYINT, TYPE_SMALLINT, TYPE_INT, TYPE_BIGINT,
64
7
                                           TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE>;
65
7
    factory.register_function_both("percentile", creator::creator<AggregateFunctionPercentile>);
66
7
    factory.register_function_both("percentile_array",
67
7
                                   creator::creator<AggregateFunctionPercentileArray>);
68
7
    factory.register_function_both("percentile_v2",
69
7
                                   creator::creator<AggregateFunctionPercentileV2>);
70
7
    factory.register_function_both("percentile_array_v2",
71
7
                                   creator::creator<AggregateFunctionPercentileArrayV2>);
72
7
    factory.register_alias("percentile", "percentile_cont");
73
7
}
74
75
6
void register_percentile_approx_old_function(AggregateFunctionSimpleFactory& factory) {
76
6
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_approx");
77
6
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_approx_weighted");
78
6
}
79
80
6
void register_aggregate_function_percentile_old(AggregateFunctionSimpleFactory& factory) {
81
6
    BeExecVersionManager::registe_restrict_function_compatibility("percentile");
82
6
    BeExecVersionManager::registe_restrict_function_compatibility("percentile_array");
83
6
}
84
85
6
void register_aggregate_function_percentile_approx(AggregateFunctionSimpleFactory& factory) {
86
6
    factory.register_function_both("percentile_approx",
87
6
                                   create_aggregate_function_percentile_approx);
88
6
    factory.register_function_both("percentile_approx_weighted",
89
6
                                   create_aggregate_function_percentile_approx_weighted);
90
91
6
    register_percentile_approx_old_function(factory);
92
6
}
93
94
} // namespace doris