github-actions[bot] commented on code in PR #30983:
URL: https://github.com/apache/doris/pull/30983#discussion_r1482379028


##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stdint.h'; consider using 
'cstdint' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstdint>
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>

Review Comment:
   warning: inclusion of deprecated C++ header 'stddef.h'; consider using 
'cstddef' instead [modernize-deprecated-headers]
   
   ```suggestion
   #include <cstddef>
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;

Review Comment:
   warning: use default member initializer for 'sum_xy' 
[modernize-use-default-member-init]
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:61:
   ```diff
   -     BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
   +     BaseData() : sum_x(0.0), sum_y(0.0), , count(0) {}
   ```
   
   ```suggestion
       double sum_xy{0.0};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;

Review Comment:
   warning: use default member initializer for 'sum_y' 
[modernize-use-default-member-init]
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:61:
   ```diff
   -     BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
   +     BaseData() : sum_x(0.0), , sum_xy(0.0), count(0) {}
   ```
   
   ```suggestion
       double sum_y{0.0};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {

Review Comment:
   warning: nested namespaces can be concatenated 
[modernize-concat-nested-namespaces]
   
   ```suggestion
   namespace doris::vectorized {
   ```
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:54:
   ```diff
   - } // namespace vectorized
   - } // namespace doris
   + } // namespace doris
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;

Review Comment:
   warning: use default member initializer for 'sum_x' 
[modernize-use-default-member-init]
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:61:
   ```diff
   -     BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
   +     BaseData() : , sum_y(0.0), sum_xy(0.0), count(0) {}
   ```
   
   ```suggestion
       double sum_x{0.0};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;
+};
+
+template <typename T>
+struct BaseDatadecimal {
+    BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
+    virtual ~BaseDatadecimal() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = DecimalV2Value();
+        sum_y = DecimalV2Value();
+        sum_xy = DecimalV2Value();
+        count = {};
+    }
+
+    DecimalV2Value get_pop_result() const {
+        if (count == 1) {
+            return DecimalV2Value();
+        }
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));
+        return sum_xy / count_dec - sum_x * sum_y / (count_dec * count_dec);
+    }
+
+    DecimalV2Value get_samp_result() const {
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));
+        DecimalV2Value one = DecimalV2Value(static_cast<int128_t>(1));
+        return sum_xy / (count_dec - one) - sum_x * sum_y / (count_dec * 
(count_dec - one));
+    }
+
+    void merge(const BaseDatadecimal& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        auto source_data_x = get_source_data(column_x, row_num);
+        auto source_data_y = get_source_data(column_y, row_num);
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    DecimalV2Value get_source_data(const IColumn* column, size_t row_num) {
+        const auto& sources = assert_cast<const ColumnDecimal<T>&>(*column);
+        Field field = sources[row_num];
+        auto decimal_field = field.template get<DecimalField<T>>();
+        int128_t value;
+        if (decimal_field.get_scale() > DecimalV2Value::SCALE) {
+            value = static_cast<int128_t>(decimal_field.get_value()) /
+                    (decimal_field.get_scale_multiplier() / 
DecimalV2Value::ONE_BILLION);
+        } else {
+            value = static_cast<int128_t>(decimal_field.get_value()) *
+                    (DecimalV2Value::ONE_BILLION / 
decimal_field.get_scale_multiplier());
+        }
+        return DecimalV2Value(value);
+    }
+
+    static DataTypePtr get_return_type() {
+        return std::make_shared<DataTypeDecimal<Decimal128V2>>(27, 9);
+    }
+
+    DecimalV2Value sum_x;
+    DecimalV2Value sum_y;
+    DecimalV2Value sum_xy;
+    int64_t count;

Review Comment:
   warning: use default member initializer for 'count' 
[modernize-use-default-member-init]
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:129:
   ```diff
   -     BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
   +     BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), {}
   ```
   
   ```suggestion
       int64_t count{0};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;
+};
+
+template <typename T>
+struct BaseDatadecimal {
+    BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
+    virtual ~BaseDatadecimal() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = DecimalV2Value();
+        sum_y = DecimalV2Value();
+        sum_xy = DecimalV2Value();
+        count = {};
+    }
+
+    DecimalV2Value get_pop_result() const {
+        if (count == 1) {
+            return DecimalV2Value();
+        }
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));
+        return sum_xy / count_dec - sum_x * sum_y / (count_dec * count_dec);
+    }
+
+    DecimalV2Value get_samp_result() const {
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));

Review Comment:
   warning: use auto when initializing with a cast to avoid duplicating the 
type name [modernize-use-auto]
   
   ```suggestion
           auto count_dec = DecimalV2Value(static_cast<int128_t>(count));
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>

Review Comment:
   warning: 'boost/iterator/iterator_facade.hpp' file not found 
[clang-diagnostic-error]
   ```cpp
   #include <boost/iterator/iterator_facade.hpp>
            ^
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;
+};
+
+template <typename T>
+struct BaseDatadecimal {
+    BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
+    virtual ~BaseDatadecimal() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = DecimalV2Value();
+        sum_y = DecimalV2Value();
+        sum_xy = DecimalV2Value();
+        count = {};
+    }
+
+    DecimalV2Value get_pop_result() const {
+        if (count == 1) {
+            return DecimalV2Value();

Review Comment:
   warning: avoid repeating the return type from the declaration; use a braced 
initializer list instead [modernize-return-braced-init-list]
   
   ```suggestion
               return {};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;
+};
+
+template <typename T>
+struct BaseDatadecimal {
+    BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
+    virtual ~BaseDatadecimal() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = DecimalV2Value();
+        sum_y = DecimalV2Value();
+        sum_xy = DecimalV2Value();
+        count = {};
+    }
+
+    DecimalV2Value get_pop_result() const {
+        if (count == 1) {
+            return DecimalV2Value();
+        }
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));
+        return sum_xy / count_dec - sum_x * sum_y / (count_dec * count_dec);
+    }
+
+    DecimalV2Value get_samp_result() const {
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));
+        DecimalV2Value one = DecimalV2Value(static_cast<int128_t>(1));

Review Comment:
   warning: use auto when initializing with a cast to avoid duplicating the 
type name [modernize-use-auto]
   
   ```suggestion
           auto one = DecimalV2Value(static_cast<int128_t>(1));
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;

Review Comment:
   warning: use default member initializer for 'count' 
[modernize-use-default-member-init]
   
   be/src/vec/aggregate_functions/aggregate_function_covar.h:61:
   ```diff
   -     BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
   +     BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), {}
   ```
   
   ```suggestion
       int64_t count{0};
   ```
   



##########
be/src/vec/aggregate_functions/aggregate_function_covar.h:
##########
@@ -0,0 +1,331 @@
+// 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
+
+#define POP true
+#define NOTPOP false
+#define NULLABLE true
+#define NOTNULLABLE false
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include <algorithm>
+#include <boost/iterator/iterator_facade.hpp>
+#include <cmath>
+#include <memory>
+#include <type_traits>
+
+#include "olap/olap_common.h"
+#include "runtime/decimalv2_value.h"
+#include "vec/aggregate_functions/aggregate_function.h"
+#include "vec/columns/column.h"
+#include "vec/columns/column_nullable.h"
+#include "vec/common/assert_cast.h"
+#include "vec/core/field.h"
+#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 {
+class Arena;
+class BufferReadable;
+class BufferWritable;
+template <typename T>
+class ColumnDecimal;
+template <typename>
+class ColumnVector;
+} // namespace vectorized
+} // namespace doris
+
+namespace doris::vectorized {
+
+template <typename T>
+struct BaseData {
+    BaseData() : sum_x(0.0), sum_y(0.0), sum_xy(0.0), count(0) {}
+    virtual ~BaseData() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = 0.0;
+        sum_y = 0.0;
+        sum_xy = 0.0;
+        count = 0;
+    }
+
+    // Cov(X, Y) = E(XY) - E(X)E(Y)
+    double get_pop_result() const {
+        if (count == 1) {
+            return 0.0;
+        }
+        return sum_xy / count - sum_x * sum_y / (count * count);
+    }
+
+    double get_samp_result() const {
+        return sum_xy / (count - 1) - sum_x * sum_y / (count * (count - 1));
+    }
+
+    void merge(const BaseData& rhs) {
+        if (rhs.count == 0) {
+            return;
+        }
+        sum_x += rhs.sum_x;
+        sum_y += rhs.sum_y;
+        sum_xy += rhs.sum_xy;
+        count += rhs.count;
+    }
+
+    void add(const IColumn* column_x, const IColumn* column_y, size_t row_num) 
{
+        const auto& sources_x = assert_cast<const ColumnVector<T>&>(*column_x);
+        double source_data_x = sources_x.get_data()[row_num];
+        const auto& sources_y = assert_cast<const ColumnVector<T>&>(*column_y);
+        double source_data_y = sources_y.get_data()[row_num];
+
+        sum_x += source_data_x;
+        sum_y += source_data_y;
+        sum_xy += source_data_x * source_data_y;
+        count += 1;
+    }
+
+    static DataTypePtr get_return_type() { return 
std::make_shared<DataTypeNumber<Float64>>(); }
+
+    double sum_x;
+    double sum_y;
+    double sum_xy;
+    int64_t count;
+};
+
+template <typename T>
+struct BaseDatadecimal {
+    BaseDatadecimal() : sum_x(0), sum_y(0), sum_xy(0), count(0) {}
+    virtual ~BaseDatadecimal() = default;
+
+    void write(BufferWritable& buf) const {
+        write_binary(sum_x, buf);
+        write_binary(sum_y, buf);
+        write_binary(sum_xy, buf);
+        write_binary(count, buf);
+    }
+
+    void read(BufferReadable& buf) {
+        read_binary(sum_x, buf);
+        read_binary(sum_y, buf);
+        read_binary(sum_xy, buf);
+        read_binary(count, buf);
+    }
+
+    void reset() {
+        sum_x = DecimalV2Value();
+        sum_y = DecimalV2Value();
+        sum_xy = DecimalV2Value();
+        count = {};
+    }
+
+    DecimalV2Value get_pop_result() const {
+        if (count == 1) {
+            return DecimalV2Value();
+        }
+        DecimalV2Value count_dec = 
DecimalV2Value(static_cast<int128_t>(count));

Review Comment:
   warning: use auto when initializing with a cast to avoid duplicating the 
type name [modernize-use-auto]
   
   ```suggestion
           auto count_dec = DecimalV2Value(static_cast<int128_t>(count));
   ```
   



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