adonis0147 commented on code in PR #9056: URL: https://github.com/apache/incubator-doris/pull/9056#discussion_r895713917
########## be/src/vec/aggregate_functions/aggregate_function_product.h: ########## @@ -0,0 +1,137 @@ +// 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 <cstddef> +#include <type_traits> + +#include "vec/aggregate_functions/aggregate_function.h" +#include "vec/columns/column_decimal.h" +#include "vec/columns/column_vector.h" +#include "vec/common/arena.h" +#include "vec/common/string_buffer.hpp" +#include "vec/core/types.h" +#include "vec/data_types/data_type_decimal.h" +#include "vec/data_types/data_type_number.h" +#include "vec/io/io_helper.h" + +namespace doris { +namespace vectorized { + +template <typename T> +struct AggregateFunctionProductData { + T product {}; + bool has_data = false; Review Comment: Removed. ########## be/src/vec/functions/array/function_array_aggregation.cpp: ########## @@ -0,0 +1,300 @@ +// 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. +// This file is copied from +// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/array/arrayAggregation.cpp +// and modified by Doris + +#include <type_traits> + +#include "vec/aggregate_functions/aggregate_function_avg.h" +#include "vec/aggregate_functions/aggregate_function_min_max.h" +#include "vec/aggregate_functions/aggregate_function_null.h" +#include "vec/aggregate_functions/aggregate_function_product.h" +#include "vec/aggregate_functions/aggregate_function_sum.h" +#include "vec/aggregate_functions/helpers.h" +#include "vec/columns/column_nullable.h" +#include "vec/common/arena.h" +#include "vec/core/types.h" +#include "vec/data_types/data_type.h" +#include "vec/data_types/data_type_nullable.h" +#include "vec/functions/array/function_array_mapped.h" +#include "vec/functions/simple_function_factory.h" + +namespace doris { +namespace vectorized { + +enum class AggregateOperation { MIN, MAX, SUM, AVERAGE, PRODUCT }; + +template <typename Element, AggregateOperation operation> +struct ArrayAggregateResultImpl; + +template <typename Element> +struct ArrayAggregateResultImpl<Element, AggregateOperation::MIN> { + using Result = Element; +}; + +template <typename Element> +struct ArrayAggregateResultImpl<Element, AggregateOperation::MAX> { + using Result = Element; +}; + +template <typename Element> +struct ArrayAggregateResultImpl<Element, AggregateOperation::AVERAGE> { + using Result = std::conditional_t<IsDecimalNumber<Element>, Decimal128, Float64>; +}; + +template <typename Element> +struct ArrayAggregateResultImpl<Element, AggregateOperation::PRODUCT> { + using Result = std::conditional_t<IsDecimalNumber<Element>, Decimal128, Float64>; +}; + +template <typename Element> +struct ArrayAggregateResultImpl<Element, AggregateOperation::SUM> { + using Result = std::conditional_t< + IsDecimalNumber<Element>, Decimal128, + std::conditional_t<IsFloatNumber<Element>, Float64, + std::conditional_t<std::is_same_v<Element, Int128>, Int128, Int64>>>; +}; + +template <typename Element, AggregateOperation operation> +using ArrayAggregateResult = typename ArrayAggregateResultImpl<Element, operation>::Result; + +template <AggregateOperation operation> +struct AggregateFunctionImpl; + +template <> +struct AggregateFunctionImpl<AggregateOperation::SUM> { + template <typename Element> + struct TypeTraits { + using ResultType = ArrayAggregateResult<Element, AggregateOperation::SUM>; + using AggregateDataType = AggregateFunctionSumData<ResultType>; + using Function = AggregateFunctionSum<Element, ResultType, AggregateDataType>; + }; +}; + +template <> +struct AggregateFunctionImpl<AggregateOperation::AVERAGE> { + template <typename Element> + struct TypeTraits { + struct AggregateDataType : public AggregateFunctionAvgData<Element> { Review Comment: Removed. -- 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