account for null values in the stddev post aggregator (#15660)

This commit is contained in:
Laksh Singla 2024-01-16 19:57:33 +05:30 committed by GitHub
parent 6b951b94c0
commit 8ba06cf723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -79,7 +79,11 @@ public class StandardDeviationPostAggregator implements PostAggregator
@Nullable
public Double compute(Map<String, Object> combinedAggregators)
{
Double variance = ((VarianceAggregatorCollector) combinedAggregators.get(fieldName)).getVariance(isVariancePop);
Object varianceAggregatorCollector = combinedAggregators.get(fieldName);
if (!(varianceAggregatorCollector instanceof VarianceAggregatorCollector)) {
return NullHandling.defaultDoubleValue();
}
Double variance = ((VarianceAggregatorCollector) varianceAggregatorCollector).getVariance(isVariancePop);
return variance == null ? NullHandling.defaultDoubleValue() : (Double) Math.sqrt(variance);
}