@Override public InternalAvg doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; double compensation = 0; // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. for (InternalAggregation aggregation : aggregations) { InternalAvg avg = (InternalAvg) aggregation; count += avg.count; if (Double.isFinite(avg.sum) == false) { sum += avg.sum; } else if (Double.isFinite(sum)) { double corrected = avg.sum - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } } return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); }
@Override public InternalAvg doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; for (InternalAggregation aggregation : aggregations) { count += ((InternalAvg) aggregation).count; sum += ((InternalAvg) aggregation).sum; } return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); }
@Override public InternalAvg doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; for (InternalAggregation aggregation : aggregations) { count += ((InternalAvg) aggregation).count; sum += ((InternalAvg) aggregation).sum; } return new InternalAvg(getName(), sum, count, valueFormatter, pipelineAggregators(), getMetaData()); }
@Override public InternalAvg doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; double compensation = 0; // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. for (InternalAggregation aggregation : aggregations) { InternalAvg avg = (InternalAvg) aggregation; count += avg.count; if (Double.isFinite(avg.sum) == false) { sum += avg.sum; } else if (Double.isFinite(sum)) { double corrected = avg.sum - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } } return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); }
@Override public InternalAvg doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { long count = 0; double sum = 0; double compensation = 0; // Compute the sum of double values with Kahan summation algorithm which is more // accurate than naive summation. for (InternalAggregation aggregation : aggregations) { InternalAvg avg = (InternalAvg) aggregation; count += avg.count; if (Double.isFinite(avg.sum) == false) { sum += avg.sum; } else if (Double.isFinite(sum)) { double corrected = avg.sum - compensation; double newSum = sum + corrected; compensation = (newSum - sum) - corrected; sum = newSum; } } return new InternalAvg(getName(), sum, count, format, pipelineAggregators(), getMetaData()); }