|
64 | 64 | import org.opensearch.search.aggregations.metrics.ValueCountAggregationBuilder;
|
65 | 65 | import org.junit.After;
|
66 | 66 | import org.junit.Before;
|
| 67 | +import org.opensearch.search.aggregations.support.ValuesSourceAggregatorFactory; |
67 | 68 |
|
68 | 69 | import java.io.IOException;
|
69 | 70 | import java.util.ArrayList;
|
|
74 | 75 | import java.util.function.BiConsumer;
|
75 | 76 | import java.util.function.Function;
|
76 | 77 |
|
77 |
| -import org.mockito.Mockito; |
78 |
| - |
| 78 | +import static org.mockito.Mockito.mock; |
| 79 | +import static org.mockito.Mockito.when; |
79 | 80 | import static org.opensearch.search.aggregations.AggregationBuilders.avg;
|
80 | 81 | import static org.opensearch.search.aggregations.AggregationBuilders.count;
|
81 | 82 | import static org.opensearch.search.aggregations.AggregationBuilders.max;
|
@@ -290,10 +291,10 @@ public void testStarTreeDocValues() throws IOException {
|
290 | 291 | new MockBigArrays(new MockPageCacheRecycler(Settings.EMPTY), circuitBreakerService).withCircuitBreaking()
|
291 | 292 | );
|
292 | 293 |
|
293 |
| - MetricAggregatorFactory aggregatorFactory = Mockito.mock(MetricAggregatorFactory.class); |
294 |
| - Mockito.when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY); |
295 |
| - Mockito.when(aggregatorFactory.getField()).thenReturn(FIELD_NAME); |
296 |
| - Mockito.when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM); |
| 294 | + MetricAggregatorFactory aggregatorFactory = mock(MetricAggregatorFactory.class); |
| 295 | + when(aggregatorFactory.getSubFactories()).thenReturn(AggregatorFactories.EMPTY); |
| 296 | + when(aggregatorFactory.getField()).thenReturn(FIELD_NAME); |
| 297 | + when(aggregatorFactory.getMetricStat()).thenReturn(MetricStat.SUM); |
297 | 298 |
|
298 | 299 | // Case when field and metric type in aggregation are fully supported by star tree.
|
299 | 300 | testCase(
|
@@ -338,6 +339,52 @@ public void testStarTreeDocValues() throws IOException {
|
338 | 339 | false
|
339 | 340 | );
|
340 | 341 |
|
| 342 | + // Case when field is not present in supported metrics |
| 343 | + testCase( |
| 344 | + indexSearcher, |
| 345 | + query, |
| 346 | + queryBuilder, |
| 347 | + sumAggregationBuilder, |
| 348 | + starTree, |
| 349 | + supportedDimensions, |
| 350 | + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), |
| 351 | + verifyAggregation(InternalSum::getValue), |
| 352 | + aggregatorFactory, |
| 353 | + false |
| 354 | + ); |
| 355 | + |
| 356 | + AggregatorFactories aggregatorFactories = mock(AggregatorFactories.class); |
| 357 | + when(aggregatorFactories.getFactories()).thenReturn(new AggregatorFactory[]{mock(MetricAggregatorFactory.class)}); |
| 358 | + when(aggregatorFactory.getSubFactories()).thenReturn(aggregatorFactories); |
| 359 | + |
| 360 | + // Case when sub aggregations are present |
| 361 | + testCase( |
| 362 | + indexSearcher, |
| 363 | + query, |
| 364 | + queryBuilder, |
| 365 | + sumAggregationBuilder, |
| 366 | + starTree, |
| 367 | + supportedDimensions, |
| 368 | + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), |
| 369 | + verifyAggregation(InternalSum::getValue), |
| 370 | + aggregatorFactory, |
| 371 | + false |
| 372 | + ); |
| 373 | + |
| 374 | + // Case when aggregation factory is not metric aggregation |
| 375 | + testCase( |
| 376 | + indexSearcher, |
| 377 | + query, |
| 378 | + queryBuilder, |
| 379 | + sumAggregationBuilder, |
| 380 | + starTree, |
| 381 | + supportedDimensions, |
| 382 | + List.of(new Metric("hello", List.of(MetricStat.MAX, MetricStat.MIN, MetricStat.AVG))), |
| 383 | + verifyAggregation(InternalSum::getValue), |
| 384 | + mock(ValuesSourceAggregatorFactory.class), |
| 385 | + false |
| 386 | + ); |
| 387 | + |
341 | 388 | ir.close();
|
342 | 389 | directory.close();
|
343 | 390 | }
|
|
0 commit comments