|
21 | 21 |
|
22 | 22 | import org.apache.lucene.util.TestUtil;
|
23 | 23 | import org.elasticsearch.search.DocValueFormat;
|
| 24 | +import org.elasticsearch.search.aggregations.InternalAggregation; |
24 | 25 | import org.elasticsearch.search.aggregations.InternalAggregations;
|
25 | 26 | import org.elasticsearch.search.aggregations.InternalMultiBucketAggregationTestCase;
|
26 | 27 | import org.elasticsearch.search.aggregations.ParsedMultiBucketAggregation;
|
27 | 28 | import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
28 | 29 |
|
29 | 30 | import java.util.ArrayList;
|
| 31 | +import java.util.Arrays; |
30 | 32 | import java.util.List;
|
31 | 33 | import java.util.Map;
|
32 | 34 |
|
@@ -59,6 +61,27 @@ protected InternalHistogram createTestInstance(String name,
|
59 | 61 | return new InternalHistogram(name, buckets, order, 1, null, format, keyed, pipelineAggregators, metaData);
|
60 | 62 | }
|
61 | 63 |
|
| 64 | + // issue 26787 |
| 65 | + public void testHandlesNaN() { |
| 66 | + InternalHistogram histogram = createTestInstance(); |
| 67 | + InternalHistogram histogram2 = createTestInstance(); |
| 68 | + List<InternalHistogram.Bucket> buckets = histogram.getBuckets(); |
| 69 | + if (buckets == null || buckets.isEmpty()) { |
| 70 | + return; |
| 71 | + } |
| 72 | + |
| 73 | + // Set the key of one bucket to NaN. Must be the last bucket because NaN is greater than everything else. |
| 74 | + List<InternalHistogram.Bucket> newBuckets = new ArrayList<>(buckets.size()); |
| 75 | + if (buckets.size() > 1) { |
| 76 | + newBuckets.addAll(buckets.subList(0, buckets.size() - 1)); |
| 77 | + } |
| 78 | + InternalHistogram.Bucket b = buckets.get(buckets.size() - 1); |
| 79 | + newBuckets.add(new InternalHistogram.Bucket(Double.NaN, b.docCount, keyed, b.format, b.aggregations)); |
| 80 | + |
| 81 | + InternalHistogram newHistogram = histogram.create(newBuckets); |
| 82 | + newHistogram.doReduce(Arrays.asList(newHistogram, histogram2), new InternalAggregation.ReduceContext(null, null, false)); |
| 83 | + } |
| 84 | + |
62 | 85 | @Override
|
63 | 86 | protected Class<? extends ParsedMultiBucketAggregation> implementationClass() {
|
64 | 87 | return ParsedHistogram.class;
|
|
0 commit comments