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