HappenLee commented on code in PR #40945: URL: https://github.com/apache/doris/pull/40945#discussion_r1768032888
########## be/src/vec/aggregate_functions/aggregate_function_statistic.h: ########## @@ -0,0 +1,162 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#pragma once +#include <cmath> +#include <cstdint> +#include <string> +#include <type_traits> + +#include "common/exception.h" +#include "common/status.h" +#include "moments.h" +#include "vec/aggregate_functions/aggregate_function.h" +#include "vec/aggregate_functions/moments.h" +#include "vec/columns/column_nullable.h" +#include "vec/columns/column_vector.h" +#include "vec/common/assert_cast.h" +#include "vec/core/types.h" +#include "vec/data_types/data_type.h" +#include "vec/data_types/data_type_nullable.h" +#include "vec/data_types/data_type_number.h" + +namespace doris::vectorized { + +enum class StatisticsFunctionKind : uint8_t { skewPop, kurtPop }; + +inline std::string to_string(StatisticsFunctionKind kind) { + switch (kind) { + case StatisticsFunctionKind::skewPop: + return "skewness"; + case StatisticsFunctionKind::kurtPop: + return "kurtosis"; + default: + return "Unknown"; + } +} + +template <typename T, std::size_t _level> +struct StatFuncOneArg { + using Type1 = T; + using Type2 = T; + using ResultType = Float64; + using Data = VarMoments<ResultType, _level>; + + static constexpr UInt32 num_args = 1; +}; + +template <typename StatFunc, bool NullableInput> +class AggregateFunctionVarianceSimple + : public IAggregateFunctionDataHelper< + typename StatFunc::Data, + AggregateFunctionVarianceSimple<StatFunc, NullableInput>> { +public: + using T1 = typename StatFunc::Type1; + using T2 = typename StatFunc::Type2; + using ColVecT1 = ColumnVectorOrDecimal<T1>; + using ColVecT2 = ColumnVectorOrDecimal<T2>; + using ResultType = typename StatFunc::ResultType; + using ColVecResult = ColumnVector<ResultType>; + + explicit AggregateFunctionVarianceSimple(StatisticsFunctionKind kind_, + const DataTypes& argument_types_) + : IAggregateFunctionDataHelper< + typename StatFunc::Data, + AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_), + kind(kind_) { + DCHECK(!argument_types_.empty()); + } + + String get_name() const override { return to_string(kind); } + + DataTypePtr get_return_type() const override { + return make_nullable(std::make_shared<DataTypeFloat64>()); + } + + void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num, + Arena*) const override { + if constexpr (NullableInput) { Review Comment: should skip the null value -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org