lidavidm commented on a change in pull request #10931:
URL: https://github.com/apache/arrow/pull/10931#discussion_r691232175



##########
File path: cpp/src/arrow/compute/kernels/aggregate_test.cc
##########
@@ -556,6 +641,98 @@ TYPED_TEST(TestNumericProductKernel, 
ScalarAggregateOptions) {
               ResultWith(null_result));
 }
 
+TEST(TestDecimalProductKernel, SimpleProduct) {
+  for (const auto& ty : {decimal128(3, 2), decimal256(3, 2)}) {
+    Datum null = ScalarFromJSON(ty, R"(null)");
+
+    EXPECT_THAT(Product(ArrayFromJSON(ty, R"([])")), ResultWith(null));
+    EXPECT_THAT(Product(ArrayFromJSON(ty, R"([null])")), ResultWith(null));
+    EXPECT_THAT(
+        Product(ArrayFromJSON(ty, R"(["0.00", "1.00", "2.00", "3.00", "4.00", 
"5.00"])")),
+        ResultWith(ScalarFromJSON(ty, R"("0.00")")));
+    Datum chunks =
+        ChunkedArrayFromJSON(ty, {R"(["1.00", "2.00", "3.00", "4.00", 
"5.00"])"});

Review comment:
       Good pointed, updated the tests.

##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic.cc
##########
@@ -187,31 +188,32 @@ struct ProductImpl : public ScalarAggregator {
     const auto& other = checked_cast<const ThisType&>(src);
     this->count += other.count;
     this->product =
-        static_cast<ProductType>(to_unsigned(this->product) * 
to_unsigned(other.product));
+        MultiplyTraits<AccType>::Multiply(*out_type, this->product, 
other.product);
     return Status::OK();
   }
 
   Status Finalize(KernelContext*, Datum* out) override {
     if (this->count < options.min_count) {
-      out->value = std::make_shared<OutputType>();
+      out->value = std::make_shared<OutputType>(out_type);
     } else {
-      out->value = MakeScalar(this->product);
+      out->value = std::make_shared<OutputType>(this->product, out_type);
     }
     return Status::OK();
   }
 
-  size_t count = 0;
-  typename AccType::c_type product = 1;
+  std::shared_ptr<DataType> out_type;

Review comment:
       I don't think we want this as the reference may be invalidated.




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


Reply via email to