Coverage Report

Created: 2026-04-11 14:25

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