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


##########
be/src/vec/functions/array/function_array_aggregation.cpp:
##########
@@ -0,0 +1,312 @@
+// 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 <condition_variable>
+#include <type_traits>
+
+#include "vec/common/arithmetic_overflow.h"
+#include "vec/core/types.h"
+#include "vec/data_types/data_type_array.h"
+#include "vec/data_types/data_type_decimal.h"
+#include "vec/data_types/data_type_number.h"
+#include "vec/functions/array/function_array_mapped.h"
+#include "vec/functions/simple_function_factory.h"
+
+namespace doris {
+namespace vectorized {
+
+enum class AggregationStatus {
+    MISMATCHED_TYPE = 0,
+    OK,
+    MATH_OVERFLOW,
+    SCALE_OUT_OF_BOUNDS,
+};
+
+enum class AggregateOperation { MIN, MAX, SUM, AVERAGE, PRODUCT };
+
+/**
+ * During array aggregation we derive result type from operation.
+ * For array min or array max we use array element as result type.
+ * For array average we use Float64.
+ * For array sum for for big integers, we use same type representation, 
decimal numbers we use Decimal128,
+ * for floating point numbers Float64, for numeric unsigned Int64, and for 
numeric signed UInt64.
+ */
+
+template <typename ArrayElement, AggregateOperation operation>
+struct ArrayAggregateResultImpl;
+
+template <typename ArrayElement>
+struct ArrayAggregateResultImpl<ArrayElement, AggregateOperation::MIN> {
+    using Result = ArrayElement;
+};
+
+template <typename ArrayElement>
+struct ArrayAggregateResultImpl<ArrayElement, AggregateOperation::MAX> {
+    using Result = ArrayElement;
+};
+
+template <typename ArrayElement>
+struct ArrayAggregateResultImpl<ArrayElement, AggregateOperation::AVERAGE> {
+    using Result = Float64;
+};
+
+template <typename ArrayElement>
+struct ArrayAggregateResultImpl<ArrayElement, AggregateOperation::PRODUCT> {
+    using Result = Float64;
+};
+
+template <typename ArrayElement>
+struct ArrayAggregateResultImpl<ArrayElement, AggregateOperation::SUM> {
+    using Result = std::conditional_t<

Review Comment:
   I think the result of the operation `SUM` should be as big as possible in 
case of math overflow. This logic is consistent with `ClickHouse`.



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

Reply via email to