1414import org .apache .lucene .document .SortedNumericDocValuesField ;
1515import org .apache .lucene .tests .index .RandomIndexWriter ;
1616import org .apache .lucene .util .NumericUtils ;
17+ import org .elasticsearch .common .time .DateFormatter ;
1718import org .elasticsearch .core .CheckedConsumer ;
19+ import org .elasticsearch .index .mapper .DateFieldMapper ;
1820import org .elasticsearch .index .mapper .MappedFieldType ;
1921import org .elasticsearch .index .mapper .NumberFieldMapper ;
2022import org .elasticsearch .search .aggregations .AggregatorTestCase ;
2123import org .elasticsearch .search .aggregations .support .AggregationInspectionHelper ;
2224
2325import java .io .IOException ;
26+ import java .util .Map ;
2427import java .util .function .Consumer ;
2528
2629import static java .util .Collections .singleton ;
30+ import static org .elasticsearch .search .aggregations .AggregationBuilders .stats ;
2731
2832public class ExtendedStatsAggregatorTests extends AggregatorTestCase {
2933 private static final double TOLERANCE = 1e-5 ;
@@ -49,6 +53,37 @@ public void testEmpty() throws IOException {
4953 });
5054 }
5155
56+ public void testEmptyDate () throws IOException {
57+ DateFormatter .forPattern ("epoch_millis" );
58+ final MappedFieldType ft = new DateFieldMapper .DateFieldType (
59+ "field" ,
60+ true ,
61+ true ,
62+ false ,
63+ true ,
64+ DateFormatter .forPattern ("epoch_millis" ),
65+ DateFieldMapper .Resolution .MILLISECONDS ,
66+ null ,
67+ null ,
68+ Map .of ()
69+ );
70+ testCase (ft , iw -> {}, stats -> {
71+ assertEquals (0d , stats .getCount (), 0 );
72+ assertEquals (0d , stats .getSum (), 0 );
73+ assertEquals (Float .NaN , stats .getAvg (), 0 );
74+ assertEquals (Double .POSITIVE_INFINITY , stats .getMin (), 0 );
75+ assertEquals (Double .NEGATIVE_INFINITY , stats .getMax (), 0 );
76+ assertEquals (Double .NaN , stats .getVariance (), 0 );
77+ assertEquals (Double .NaN , stats .getVariancePopulation (), 0 );
78+ assertEquals (Double .NaN , stats .getVarianceSampling (), 0 );
79+ assertEquals (Double .NaN , stats .getStdDeviation (), 0 );
80+ assertEquals (Double .NaN , stats .getStdDeviationPopulation (), 0 );
81+ assertEquals (Double .NaN , stats .getStdDeviationSampling (), 0 );
82+ assertEquals (0d , stats .getSumOfSquares (), 0 );
83+ assertFalse (AggregationInspectionHelper .hasValue (stats ));
84+ });
85+ }
86+
5287 public void testRandomDoubles () throws IOException {
5388 MappedFieldType ft = new NumberFieldMapper .NumberFieldType ("field" , NumberFieldMapper .NumberType .DOUBLE );
5489 final ExtendedSimpleStatsAggregator expected = new ExtendedSimpleStatsAggregator ();
0 commit comments