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