36
36
import org .elasticsearch .search .aggregations .AggregationBuilder ;
37
37
import org .elasticsearch .search .aggregations .Aggregator ;
38
38
import org .elasticsearch .search .aggregations .BucketOrder ;
39
+ import org .elasticsearch .search .aggregations .InternalAggregation .ReduceContext ;
39
40
import org .elasticsearch .search .aggregations .bucket .terms .StringTerms ;
40
41
import org .elasticsearch .search .aggregations .bucket .terms .TermsAggregationBuilder ;
42
+ import org .elasticsearch .search .aggregations .pipeline .PipelineAggregator .PipelineTree ;
41
43
import org .elasticsearch .search .aggregations .support .AggregationContext ;
42
44
import org .elasticsearch .search .aggregations .support .AggregationInspectionHelper ;
43
45
import org .hamcrest .Matcher ;
@@ -1200,9 +1202,44 @@ public void testMissingValueDoesNotUseFromRange() throws IOException {
1200
1202
);
1201
1203
}
1202
1204
1205
+ public void testExtendedBoundsUsesFromRange () throws IOException {
1206
+ aggregationImplementationChoiceTestCase (
1207
+ aggregableDateFieldType (false , true , DateFormatter .forPattern ("yyyy" )),
1208
+ org .elasticsearch .common .collect .List .of ("2017" , "2018" ),
1209
+ org .elasticsearch .common .collect .List .of ("2016" , "2017" , "2018" , "2019" ),
1210
+ new DateHistogramAggregationBuilder ("test" ).field (AGGREGABLE_DATE )
1211
+ .calendarInterval (DateHistogramInterval .YEAR )
1212
+ .extendedBounds (new LongBounds ("2016" , "2019" ))
1213
+ .minDocCount (0 ),
1214
+ true
1215
+ );
1216
+ }
1217
+
1218
+ public void testHardBoundsUsesFromRange () throws IOException {
1219
+ aggregationImplementationChoiceTestCase (
1220
+ aggregableDateFieldType (false , true , DateFormatter .forPattern ("yyyy" )),
1221
+ org .elasticsearch .common .collect .List .of ("2016" , "2017" , "2018" , "2019" ),
1222
+ org .elasticsearch .common .collect .List .of ("2017" , "2018" ),
1223
+ new DateHistogramAggregationBuilder ("test" ).field (AGGREGABLE_DATE )
1224
+ .calendarInterval (DateHistogramInterval .YEAR )
1225
+ .hardBounds (new LongBounds ("2017" , "2019" )),
1226
+ true
1227
+ );
1228
+ }
1229
+
1230
+ private void aggregationImplementationChoiceTestCase (
1231
+ DateFieldMapper .DateFieldType ft ,
1232
+ List <String > data ,
1233
+ DateHistogramAggregationBuilder builder ,
1234
+ boolean usesFromRange
1235
+ ) throws IOException {
1236
+ aggregationImplementationChoiceTestCase (ft , data , data , builder , usesFromRange );
1237
+ }
1238
+
1203
1239
private void aggregationImplementationChoiceTestCase (
1204
1240
DateFieldMapper .DateFieldType ft ,
1205
1241
List <String > data ,
1242
+ List <String > resultingBucketKeys ,
1206
1243
DateHistogramAggregationBuilder builder ,
1207
1244
boolean usesFromRange
1208
1245
) throws IOException {
@@ -1227,7 +1264,14 @@ private void aggregationImplementationChoiceTestCase(
1227
1264
agg .preCollection ();
1228
1265
context .searcher ().search (context .query (), agg );
1229
1266
InternalDateHistogram result = (InternalDateHistogram ) agg .buildTopLevel ();
1230
- assertThat (result .getBuckets ().stream ().map (InternalDateHistogram .Bucket ::getKeyAsString ).collect (toList ()), equalTo (data ));
1267
+ result = (InternalDateHistogram ) result .reduce (
1268
+ org .elasticsearch .common .collect .List .of (result ),
1269
+ ReduceContext .forFinalReduction (context .bigArrays (), null , context .multiBucketConsumer (), PipelineTree .EMPTY )
1270
+ );
1271
+ assertThat (
1272
+ result .getBuckets ().stream ().map (InternalDateHistogram .Bucket ::getKeyAsString ).collect (toList ()),
1273
+ equalTo (resultingBucketKeys )
1274
+ );
1231
1275
}
1232
1276
}
1233
1277
}
0 commit comments