Align behavior or HDR percentiles iterator with percentile() method (#24206)
This commit is contained in:
parent
0e322a7e0b
commit
55a879ee8d
|
@ -98,7 +98,9 @@ public class InternalHDRPercentiles extends AbstractInternalHDRPercentiles imple
|
|||
|
||||
@Override
|
||||
public Percentile next() {
|
||||
final Percentile next = new Percentile(percents[i], state.getValueAtPercentile(percents[i]));
|
||||
double percent = percents[i];
|
||||
double value = (state.getTotalCount() == 0) ? Double.NaN : state.getValueAtPercentile(percent);
|
||||
final Percentile next = new Percentile(percent, value);
|
||||
++i;
|
||||
return next;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public abstract class InternalPercentilesTestCase<T extends InternalAggregation>
|
|||
protected abstract T createTestInstance(String name, List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData,
|
||||
boolean keyed, DocValueFormat format, double[] percents, double[] values);
|
||||
|
||||
private static double[] randomPercents() {
|
||||
protected static double[] randomPercents() {
|
||||
List<Double> randomCdfValues = randomSubsetOf(randomIntBetween(1, 7), 0.01d, 0.05d, 0.25d, 0.50d, 0.75d, 0.95d, 0.99d);
|
||||
double[] percents = new double[randomCdfValues.size()];
|
||||
for (int i = 0; i < randomCdfValues.size(); i++) {
|
||||
|
|
|
@ -23,12 +23,17 @@ import org.HdrHistogram.DoubleHistogram;
|
|||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
import org.elasticsearch.search.DocValueFormat;
|
||||
import org.elasticsearch.search.aggregations.metrics.percentiles.InternalPercentilesTestCase;
|
||||
import org.elasticsearch.search.aggregations.metrics.percentiles.Percentile;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptyMap;
|
||||
|
||||
public class InternalHDRPercentilesTests extends InternalPercentilesTestCase<InternalHDRPercentiles> {
|
||||
|
||||
@Override
|
||||
|
@ -57,4 +62,24 @@ public class InternalHDRPercentilesTests extends InternalPercentilesTestCase<Int
|
|||
protected Writeable.Reader<InternalHDRPercentiles> instanceReader() {
|
||||
return InternalHDRPercentiles::new;
|
||||
}
|
||||
|
||||
public void testIterator() {
|
||||
final double[] percents = randomPercents();
|
||||
final double[] values = new double[frequently() ? randomIntBetween(1, 10) : 0];
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
values[i] = randomDouble();
|
||||
}
|
||||
|
||||
InternalHDRPercentiles aggregation =
|
||||
createTestInstance("test", emptyList(), emptyMap(), false, randomNumericDocValueFormat(), percents, values);
|
||||
|
||||
Iterator<Percentile> iterator = aggregation.iterator();
|
||||
for (double percent : percents) {
|
||||
assertTrue(iterator.hasNext());
|
||||
|
||||
Percentile percentile = iterator.next();
|
||||
assertEquals(percent, percentile.getPercent(), 0.0d);
|
||||
assertEquals(aggregation.percentile(percent), percentile.getValue(), 0.0d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue