use of org.opensearch.search.aggregations.bucket.InternalSingleBucketAggregation in project anomaly-detection by opensearch-project.
the class AbstractRetriever method parseAggregation.
protected double parseAggregation(Aggregation aggregationToParse) {
Double result = null;
if (aggregationToParse instanceof InternalSingleBucketAggregation) {
InternalAggregations bucket = ((InternalSingleBucketAggregation) aggregationToParse).getAggregations();
if (bucket != null) {
List<Aggregation> aggrs = bucket.asList();
if (aggrs.size() == 1) {
// we only accept a single value as feature
aggregationToParse = aggrs.get(0);
}
}
}
final Aggregation aggregation = aggregationToParse;
if (aggregation instanceof SingleValue) {
result = ((SingleValue) aggregation).value();
} else if (aggregation instanceof InternalTDigestPercentiles) {
Iterator<Percentile> percentile = ((InternalTDigestPercentiles) aggregation).iterator();
if (percentile.hasNext()) {
result = percentile.next().getValue();
}
}
return Optional.ofNullable(result).orElseThrow(() -> new EndRunException("Failed to parse aggregation " + aggregation, true).countedInStats(false));
}
use of org.opensearch.search.aggregations.bucket.InternalSingleBucketAggregation in project OpenSearch by opensearch-project.
the class InternalSingleBucketAggregationTestCase method assertReduced.
@Override
protected final void assertReduced(T reduced, List<T> inputs) {
assertEquals(inputs.stream().mapToLong(InternalSingleBucketAggregation::getDocCount).sum(), reduced.getDocCount());
if (hasInternalMax) {
double expected = inputs.stream().mapToDouble(i -> {
InternalMax max = i.getAggregations().get("max");
return max.getValue();
}).max().getAsDouble();
InternalMax reducedMax = reduced.getAggregations().get("max");
assertEquals(expected, reducedMax.getValue(), 0);
}
if (hasInternalMin) {
double expected = inputs.stream().mapToDouble(i -> {
InternalMin min = i.getAggregations().get("min");
return min.getValue();
}).min().getAsDouble();
InternalMin reducedMin = reduced.getAggregations().get("min");
assertEquals(expected, reducedMin.getValue(), 0);
}
extraAssertReduced(reduced, inputs);
}
Aggregations