HappenLee commented on code in PR #9056:
URL: https://github.com/apache/incubator-doris/pull/9056#discussion_r893066739


##########
be/src/vec/functions/array/function_array_mapped.h:
##########
@@ -0,0 +1,76 @@
+// 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/FunctionArrayMapped.h
+// and modified by Doris
+
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_nullable.h"
+#include "vec/functions/function.h"
+
+namespace doris {
+namespace vectorized {
+
+/** Higher-order functions for arrays.
+  * These functions optionally apply a map (transform) to array (or multiple 
arrays of identical size) by lambda function,
+  *  and return some result based on that transformation.
+  *
+  * Examples:
+  * arrayMap(x1,...,xn -> expression, array1,...,arrayn) - apply the 
expression to each element of the array (or set of parallel arrays).
+  * arrayFilter(x -> predicate, array) - leave in the array only the elements 
for which the expression is true.
+  *
+  * For some functions arrayCount, arrayExists, arrayAll, an overload of the 
form f(array) is available,
+  *  which works in the same way as f(x -> x, array).
+  *
+  * See the example of Impl template parameter in arrayMap.cpp
+  */
+template <typename Impl, typename Name>
+class FunctionArrayMapped : public IFunction {
+public:
+    static constexpr auto name = Name::name;
+    static FunctionPtr create() { return 
std::make_shared<FunctionArrayMapped>(); }
+
+    String get_name() const override { return name; }
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) override {
+        const auto& typed_column = block.get_by_position(arguments[0]);
+        const typename Impl::column_type* column_array;
+        if (typed_column.column->is_nullable()) {

Review Comment:
   should delele the judge of `if (typed_column.column->is_nullable())`, 
because set the `use_default_implementation_for_nulls()` is `true`



##########
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:
   useless clase to dispose `[]`, delete it



##########
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:
   useless `has_data` 



##########
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> {

Review Comment:
   Add conment of why MIN/MAX do have AggregateFunctionImpl



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to