diff --git a/velox/functions/lib/aggregates/CentralMomentsAggregatesBase.h b/velox/functions/lib/aggregates/CentralMomentsAggregatesBase.h index d0bd97874715b..1e3035b0ccf3a 100644 --- a/velox/functions/lib/aggregates/CentralMomentsAggregatesBase.h +++ b/velox/functions/lib/aggregates/CentralMomentsAggregatesBase.h @@ -32,7 +32,7 @@ struct CentralMomentsIndices { constexpr CentralMomentsIndices kCentralMomentsIndices{0, 1, 2, 3, 4}; struct CentralMomentsAccumulator { - double count() const { + int64_t count() const { return count_; } @@ -83,6 +83,14 @@ struct CentralMomentsAccumulator { if (otherCount == 0) { return; } + if (count_ == 0) { + count_ = otherCount; + m1_ = otherM1; + m2_ = otherM2; + m3_ = otherM3; + m4_ = otherM4; + return; + } double oldCount = count(); count_ += otherCount;