be/src/exprs/aggregate/aggregate_function_skew.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 "core/data_type/data_type.h" |
19 | | #include "exprs/aggregate/aggregate_function.h" |
20 | | #include "exprs/aggregate/aggregate_function_simple_factory.h" |
21 | | #include "exprs/aggregate/aggregate_function_statistic.h" |
22 | | #include "exprs/aggregate/factory_helpers.h" |
23 | | #include "exprs/aggregate/helpers.h" |
24 | | |
25 | | namespace doris { |
26 | | |
27 | | AggregateFunctionPtr create_aggregate_function_skew(const std::string& name, |
28 | | const DataTypes& argument_types, |
29 | | const DataTypePtr& result_type, |
30 | | const bool result_is_nullable, |
31 | 26 | const AggregateFunctionAttr& attr) { |
32 | 26 | assert_arity_range(name, argument_types, 1, 1); |
33 | 26 | if (!result_is_nullable) { |
34 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, |
35 | 0 | "Aggregate function {} requires result_is_nullable", name); |
36 | 0 | } |
37 | | |
38 | 26 | const bool nullable_input = argument_types[0]->is_nullable(); |
39 | 26 | using StatFunctionTemplate = StatFuncOneArg<TYPE_DOUBLE, 3>; |
40 | | |
41 | 26 | if (nullable_input) { |
42 | 13 | return creator_without_type::create_ignore_nullable< |
43 | 13 | AggregateFunctionVarianceSimple<StatFunctionTemplate, true>>( |
44 | 13 | argument_types, result_is_nullable, attr, STATISTICS_FUNCTION_KIND::SKEW_POP); |
45 | 13 | } else { |
46 | 13 | return creator_without_type::create_ignore_nullable< |
47 | 13 | AggregateFunctionVarianceSimple<StatFunctionTemplate, false>>( |
48 | 13 | argument_types, result_is_nullable, attr, STATISTICS_FUNCTION_KIND::SKEW_POP); |
49 | 13 | } |
50 | 26 | } |
51 | | |
52 | 6 | void register_aggregate_function_skewness(AggregateFunctionSimpleFactory& factory) { |
53 | 6 | factory.register_function_both("skew", create_aggregate_function_skew); |
54 | 6 | factory.register_alias("skew", "skew_pop"); |
55 | 6 | factory.register_alias("skew", "skewness"); |
56 | 6 | } |
57 | | |
58 | | } // namespace doris |