You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/08/06 13:28:52 UTC

[GitHub] [arrow] lidavidm commented on a change in pull request #10890: ARROW-13575: [C++] Add hash_product kernel

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



##########
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:
       Ah fair point. Updated to check for overflow for integers.




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org