This is an automated email from the ASF dual-hosted git repository.

lihaopeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 5445a86570 [Bug](array_product) Fix array_product for ARRAY<DECIMAL> 
(#18014)
5445a86570 is described below

commit 5445a865709ae5a8bfdd330fe71b301fb5431c0f
Author: Gabriel <gabrielleeb...@gmail.com>
AuthorDate: Thu Mar 23 20:29:50 2023 +0800

    [Bug](array_product) Fix array_product for ARRAY<DECIMAL> (#18014)
---
 .../aggregate_function_product.h                   | 46 ++++++++++++++++++----
 .../test_array_aggregation_functions.out           |  4 +-
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/be/src/vec/aggregate_functions/aggregate_function_product.h 
b/be/src/vec/aggregate_functions/aggregate_function_product.h
index a652df4fb1..572dc19000 100644
--- a/be/src/vec/aggregate_functions/aggregate_function_product.h
+++ b/be/src/vec/aggregate_functions/aggregate_function_product.h
@@ -37,9 +37,9 @@ template <typename T>
 struct AggregateFunctionProductData {
     T product {};
 
-    void add(T value) { product *= value; }
+    void add(T value, T) { product *= value; }
 
-    void merge(const AggregateFunctionProductData& other) { product *= 
other.product; }
+    void merge(const AggregateFunctionProductData& other, T) { product *= 
other.product; }
 
     void write(BufferWritable& buffer) const { write_binary(product, buffer); }
 
@@ -54,14 +54,14 @@ template <>
 struct AggregateFunctionProductData<Decimal128> {
     Decimal128 product {};
 
-    void add(Decimal128 value) {
+    void add(Decimal128 value, Decimal128) {
         DecimalV2Value decimal_product(static_cast<Int128>(product));
         DecimalV2Value decimal_value(static_cast<Int128>(value));
         DecimalV2Value ret = decimal_product * decimal_value;
         memcpy(&product, &ret, sizeof(Decimal128));
     }
 
-    void merge(const AggregateFunctionProductData& other) {
+    void merge(const AggregateFunctionProductData& other, Decimal128) {
         DecimalV2Value decimal_product(static_cast<Int128>(product));
         DecimalV2Value decimal_value(static_cast<Int128>(other.product));
         DecimalV2Value ret = decimal_product * decimal_value;
@@ -77,6 +77,30 @@ struct AggregateFunctionProductData<Decimal128> {
     void reset(Decimal128 value) { product = std::move(value); }
 };
 
+template <>
+struct AggregateFunctionProductData<Decimal128I> {
+    Decimal128I product {};
+
+    template <typename NestedType>
+    void add(Decimal<NestedType> value, Decimal128I multiplier) {
+        product *= value;
+        product /= multiplier;
+    }
+
+    void merge(const AggregateFunctionProductData& other, Decimal128I 
multiplier) {
+        product *= other.product;
+        product /= multiplier;
+    }
+
+    void write(BufferWritable& buffer) const { write_binary(product, buffer); }
+
+    void read(BufferReadable& buffer) { read_binary(product, buffer); }
+
+    Decimal128 get() const { return product; }
+
+    void reset(Decimal128 value) { product = std::move(value); }
+};
+
 template <typename T, typename TResult, typename Data>
 class AggregateFunctionProduct final
         : public IAggregateFunctionDataHelper<Data, 
AggregateFunctionProduct<T, TResult, Data>> {
@@ -92,7 +116,12 @@ public:
     AggregateFunctionProduct(const DataTypes& argument_types_)
             : IAggregateFunctionDataHelper<Data, AggregateFunctionProduct<T, 
TResult, Data>>(
                       argument_types_),
-              scale(get_decimal_scale(*argument_types_[0])) {}
+              scale(get_decimal_scale(*argument_types_[0])) {
+        if constexpr (IsDecimalNumber<T>) {
+            multiplier =
+                    
ResultDataType::get_scale_multiplier(get_decimal_scale(*argument_types_[0]));
+        }
+    }
 
     DataTypePtr get_return_type() const override {
         if constexpr (IsDecimalNumber<T>) {
@@ -105,12 +134,12 @@ public:
     void add(AggregateDataPtr __restrict place, const IColumn** columns, 
size_t row_num,
              Arena*) const override {
         const auto& column = static_cast<const ColVecType&>(*columns[0]);
-        this->data(place).add(column.get_data()[row_num]);
+        this->data(place).add(column.get_data()[row_num], multiplier);
     }
 
     void reset(AggregateDataPtr place) const override {
         if constexpr (IsDecimalNumber<T>) {
-            this->data(place).reset(T(1 * 
ResultDataType::get_scale_multiplier(scale)));
+            this->data(place).reset(T(1 * multiplier));
         } else {
             this->data(place).reset(1);
         }
@@ -118,7 +147,7 @@ public:
 
     void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
                Arena*) const override {
-        this->data(place).merge(this->data(rhs));
+        this->data(place).merge(this->data(rhs), multiplier);
     }
 
     void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& 
buf) const override {
@@ -137,6 +166,7 @@ public:
 
 private:
     UInt32 scale;
+    TResult multiplier;
 };
 
 } // namespace vectorized
diff --git 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_aggregation_functions.out
 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_aggregation_functions.out
index 906452af47..9a9415a348 100644
--- 
a/regression-test/data/query_p0/sql_functions/array_functions/test_array_aggregation_functions.out
+++ 
b/regression-test/data/query_p0/sql_functions/array_functions/test_array_aggregation_functions.out
@@ -24,8 +24,8 @@
 4      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N
 
 -- !select --
-1      6.0     10100.0 1001000.0       4.6116860205748716E18   
9.223372036854776E18    0E-9    1.5     10000.06000005  12345654321     
49382715950617284.000   111111110888888889.000  197530863802469136.000
+1      6.0     10100.0 1001000.0       4.6116860205748716E18   
9.223372036854776E18    0E-9    1.5     10000.06000005  12345654321     
49382715950.617 111111110888.888        197530863802.469
 2      36.0    \N      \N      \N      \N      \N      16268.700775146484      
4.023   \N      \N      \N      \N
-3      -0.0    1.073709056E9   1.0737418235E14 -0.0    -1.9964567667389465E64  
-99.999980000   -0.0    -16256.02550001 12345654321     49382715950617284.000   
111111110888888889.000  197530863802469136.000
+3      -0.0    1.073709056E9   1.0737418235E14 -0.0    -1.9964567667389465E64  
-99.999980000   -0.0    -16256.02550001 12345654321     49382715950.617 
111111110888.888        197530863802.469
 4      \N      \N      \N      \N      \N      \N      \N      \N      \N      
\N      \N      \N
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to