use of org.opensearch.search.aggregations.InternalAggregation in project OpenSearch by opensearch-project.
the class InternalAvg method reduce.
@Override
public InternalAvg reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
CompensatedSum kahanSummation = new CompensatedSum(0, 0);
long count = 0;
// accurate than naive summation.
for (InternalAggregation aggregation : aggregations) {
InternalAvg avg = (InternalAvg) aggregation;
count += avg.count;
kahanSummation.add(avg.sum);
}
return new InternalAvg(getName(), kahanSummation.value(), count, format, getMetadata());
}
use of org.opensearch.search.aggregations.InternalAggregation in project OpenSearch by opensearch-project.
the class InternalMedianAbsoluteDeviation method reduce.
@Override
public InternalAggregation reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
final TDigestState valueMerged = new TDigestState(valuesSketch.compression());
for (InternalAggregation aggregation : aggregations) {
final InternalMedianAbsoluteDeviation madAggregation = (InternalMedianAbsoluteDeviation) aggregation;
valueMerged.add(madAggregation.valuesSketch);
}
return new InternalMedianAbsoluteDeviation(name, metadata, format, valueMerged);
}
use of org.opensearch.search.aggregations.InternalAggregation in project OpenSearch by opensearch-project.
the class InternalGeoBounds method reduce.
@Override
public InternalAggregation reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
double top = Double.NEGATIVE_INFINITY;
double bottom = Double.POSITIVE_INFINITY;
double posLeft = Double.POSITIVE_INFINITY;
double posRight = Double.NEGATIVE_INFINITY;
double negLeft = Double.POSITIVE_INFINITY;
double negRight = Double.NEGATIVE_INFINITY;
for (InternalAggregation aggregation : aggregations) {
InternalGeoBounds bounds = (InternalGeoBounds) aggregation;
if (bounds.top > top) {
top = bounds.top;
}
if (bounds.bottom < bottom) {
bottom = bounds.bottom;
}
if (bounds.posLeft < posLeft) {
posLeft = bounds.posLeft;
}
if (bounds.posRight > posRight) {
posRight = bounds.posRight;
}
if (bounds.negLeft < negLeft) {
negLeft = bounds.negLeft;
}
if (bounds.negRight > negRight) {
negRight = bounds.negRight;
}
}
return new InternalGeoBounds(name, top, bottom, posLeft, posRight, negLeft, negRight, wrapLongitude, getMetadata());
}
use of org.opensearch.search.aggregations.InternalAggregation in project OpenSearch by opensearch-project.
the class InternalSum method reduce.
@Override
public InternalSum reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
// Compute the sum of double values with Kahan summation algorithm which is more
// accurate than naive summation.
CompensatedSum kahanSummation = new CompensatedSum(0, 0);
for (InternalAggregation aggregation : aggregations) {
double value = ((InternalSum) aggregation).sum;
kahanSummation.add(value);
}
return new InternalSum(name, kahanSummation.value(), format, getMetadata());
}
use of org.opensearch.search.aggregations.InternalAggregation in project OpenSearch by opensearch-project.
the class AbstractInternalHDRPercentiles method reduce.
@Override
public AbstractInternalHDRPercentiles reduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) {
DoubleHistogram merged = null;
for (InternalAggregation aggregation : aggregations) {
final AbstractInternalHDRPercentiles percentiles = (AbstractInternalHDRPercentiles) aggregation;
if (merged == null) {
merged = new DoubleHistogram(percentiles.state);
merged.setAutoResize(true);
}
merged.add(percentiles.state);
}
return createReduced(getName(), keys, merged, keyed, getMetadata());
}
Aggregations