13
13
import org .apache .lucene .document .SortedNumericDocValuesField ;
14
14
import org .apache .lucene .tests .index .RandomIndexWriter ;
15
15
import org .apache .lucene .util .NumericUtils ;
16
+ import org .elasticsearch .common .time .DateFormatter ;
16
17
import org .elasticsearch .core .CheckedConsumer ;
18
+ import org .elasticsearch .index .mapper .DateFieldMapper ;
17
19
import org .elasticsearch .index .mapper .MappedFieldType ;
18
20
import org .elasticsearch .index .mapper .NumberFieldMapper ;
19
21
import org .elasticsearch .search .aggregations .AggregatorTestCase ;
20
22
import org .elasticsearch .search .aggregations .support .AggregationInspectionHelper ;
21
23
22
24
import java .io .IOException ;
25
+ import java .util .Map ;
23
26
import java .util .function .Consumer ;
24
27
25
28
import static java .util .Collections .singleton ;
29
+ import static org .elasticsearch .search .aggregations .AggregationBuilders .stats ;
26
30
27
31
public class ExtendedStatsAggregatorTests extends AggregatorTestCase {
28
32
private static final double TOLERANCE = 1e-5 ;
@@ -48,6 +52,37 @@ public void testEmpty() throws IOException {
48
52
});
49
53
}
50
54
55
+ public void testEmptyDate () throws IOException {
56
+ DateFormatter .forPattern ("epoch_millis" );
57
+ final MappedFieldType ft = new DateFieldMapper .DateFieldType (
58
+ "field" ,
59
+ true ,
60
+ true ,
61
+ false ,
62
+ true ,
63
+ DateFormatter .forPattern ("epoch_millis" ),
64
+ DateFieldMapper .Resolution .MILLISECONDS ,
65
+ null ,
66
+ null ,
67
+ Map .of ()
68
+ );
69
+ testCase (ft , iw -> {}, stats -> {
70
+ assertEquals (0d , stats .getCount (), 0 );
71
+ assertEquals (0d , stats .getSum (), 0 );
72
+ assertEquals (Float .NaN , stats .getAvg (), 0 );
73
+ assertEquals (Double .POSITIVE_INFINITY , stats .getMin (), 0 );
74
+ assertEquals (Double .NEGATIVE_INFINITY , stats .getMax (), 0 );
75
+ assertEquals (Double .NaN , stats .getVariance (), 0 );
76
+ assertEquals (Double .NaN , stats .getVariancePopulation (), 0 );
77
+ assertEquals (Double .NaN , stats .getVarianceSampling (), 0 );
78
+ assertEquals (Double .NaN , stats .getStdDeviation (), 0 );
79
+ assertEquals (Double .NaN , stats .getStdDeviationPopulation (), 0 );
80
+ assertEquals (Double .NaN , stats .getStdDeviationSampling (), 0 );
81
+ assertEquals (0d , stats .getSumOfSquares (), 0 );
82
+ assertFalse (AggregationInspectionHelper .hasValue (stats ));
83
+ });
84
+ }
85
+
51
86
public void testRandomDoubles () throws IOException {
52
87
MappedFieldType ft = new NumberFieldMapper .NumberFieldType ("field" , NumberFieldMapper .NumberType .DOUBLE );
53
88
final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator ();
0 commit comments