rok commented on a change in pull request #9758:
URL: https://github.com/apache/arrow/pull/9758#discussion_r628670779



##########
File path: cpp/src/arrow/compute/kernels/aggregate_basic_internal.h
##########
@@ -72,44 +73,54 @@ struct SumImpl : public ScalarAggregator {
 
   Status MergeFrom(KernelContext*, KernelState&& src) override {
     const auto& other = checked_cast<const ThisType&>(src);
+    this->length += other.length;
     this->count += other.count;
     this->sum += other.sum;
     return Status::OK();
   }
 
   Status Finalize(KernelContext*, Datum* out) override {
-    if (this->count == 0) {
+    if (this->count < options.min_count) {
       out->value = std::make_shared<OutputType>();
     } else {
       out->value = MakeScalar(this->sum);
     }
     return Status::OK();
   }
 
+  size_t length = 0;
   size_t count = 0;
   typename SumType::c_type sum = 0;
+  ScalarAggregateOptions options;
 };
 
 template <typename ArrowType, SimdLevel::type SimdLevel>
 struct MeanImpl : public SumImpl<ArrowType, SimdLevel> {
   Status Finalize(KernelContext*, Datum* out) override {
-    if (this->count == 0) {
+    if (this->count < options.min_count) {
       out->value = std::make_shared<DoubleScalar>();
-    } else {
+    } else if (options.skip_nulls) {
       const double mean = static_cast<double>(this->sum) / this->count;
       out->value = std::make_shared<DoubleScalar>(mean);
+    } else {
+      const double mean = static_cast<double>(this->sum) / this->length;

Review comment:
       Yeah good point. I was thinking about [this 
comment](https://issues.apache.org/jira/browse/ARROW-9054?focusedCommentId=17136725&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-17136725)
 but it would be a bit surprising. Reverting.




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

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to