cyb70289 commented on a change in pull request #10890:
URL: https://github.com/apache/arrow/pull/10890#discussion_r683931261



##########
File path: cpp/src/arrow/compute/kernels/hash_aggregate.cc
##########
@@ -1011,6 +1011,108 @@ struct GroupedSumFactory {
   InputType argument_type;
 };
 
+// ----------------------------------------------------------------------
+// Product implementation
+
+template <typename Type>
+struct GroupedProductImpl : public GroupedAggregator {
+  using AccType = typename FindAccumulatorType<Type>::Type;
+  using ProductType = typename TypeTraits<AccType>::CType;
+
+  Status Init(ExecContext* ctx, const FunctionOptions*) override {
+    pool_ = ctx->memory_pool();
+    products_ = TypedBufferBuilder<ProductType>(pool_);
+    valid_ = TypedBufferBuilder<bool>(pool_);
+    out_type_ = TypeTraits<AccType>::type_singleton();
+    return Status::OK();
+  }
+
+  Status Resize(int64_t new_num_groups) override {
+    auto added_groups = new_num_groups - num_groups_;
+    num_groups_ = new_num_groups;
+    RETURN_NOT_OK(products_.Append(added_groups * sizeof(AccType), 1));
+    RETURN_NOT_OK(valid_.Append(added_groups, false));
+    return Status::OK();
+  }
+
+  Status Consume(const ExecBatch& batch) override {
+    ProductType* products = products_.mutable_data();
+    auto valid = valid_.mutable_data();
+
+    auto g = batch[1].array()->GetValues<uint32_t>(1);
+    VisitArrayDataInline<Type>(
+        *batch[0].array(),
+        [&](typename TypeTraits<Type>::CType value) {
+          products[*g] *= value;

Review comment:
       Will it cause signed integer overflow?




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