Adapt to getProperty move out of MultiBucketsAggregation.Bucket (elastic/x-pack-elasticsearch#1015)
Adapt to getProperty move out of MultiBucketsAggregation.Bucket Original commit: elastic/x-pack-elasticsearch@3e8ca753cd
This commit is contained in:
parent
18835fe4df
commit
cb07e93fde
|
@ -112,12 +112,12 @@ class AggregationDataExtractor implements DataExtractor {
|
||||||
.setSize(0)
|
.setSize(0)
|
||||||
.setQuery(ExtractorUtils.wrapInTimeRangeQuery(context.query, context.timeField, context.start, context.end));
|
.setQuery(ExtractorUtils.wrapInTimeRangeQuery(context.query, context.timeField, context.start, context.end));
|
||||||
|
|
||||||
context.aggs.getAggregatorFactories().forEach(a -> searchRequestBuilder.addAggregation(a));
|
context.aggs.getAggregatorFactories().forEach(searchRequestBuilder::addAggregation);
|
||||||
context.aggs.getPipelineAggregatorFactories().forEach(a -> searchRequestBuilder.addAggregation(a));
|
context.aggs.getPipelineAggregatorFactories().forEach(searchRequestBuilder::addAggregation);
|
||||||
return searchRequestBuilder;
|
return searchRequestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Histogram.Bucket> getHistogramBuckets(@Nullable Aggregations aggs) {
|
private List<? extends Histogram.Bucket> getHistogramBuckets(@Nullable Aggregations aggs) {
|
||||||
if (aggs == null) {
|
if (aggs == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class AggregationDataExtractor implements DataExtractor {
|
||||||
}
|
}
|
||||||
if (aggsAsList.size() > 1) {
|
if (aggsAsList.size() > 1) {
|
||||||
throw new IllegalArgumentException("Multiple top level aggregations not supported; found: "
|
throw new IllegalArgumentException("Multiple top level aggregations not supported; found: "
|
||||||
+ aggsAsList.stream().map(a -> a.getName()).collect(Collectors.toList()));
|
+ aggsAsList.stream().map(Aggregation::getName).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Aggregation topAgg = aggsAsList.get(0);
|
Aggregation topAgg = aggsAsList.get(0);
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
createHistogramBucket(1000L, 3, Arrays.asList(
|
createHistogramBucket(1000L, 3, Arrays.asList(
|
||||||
createMax("time", 1999),
|
createMax("time", 1999),
|
||||||
createTerms("airline", new Term("a", 1, "responsetime", 11.0), new Term("b", 2, "responsetime", 12.0)))),
|
createTerms("airline", new Term("a", 1, "responsetime", 11.0), new Term("b", 2, "responsetime", 12.0)))),
|
||||||
createHistogramBucket(2000L, 0, Arrays.asList()),
|
createHistogramBucket(2000L, 0, Collections.emptyList()),
|
||||||
createHistogramBucket(3000L, 7, Arrays.asList(
|
createHistogramBucket(3000L, 7, Arrays.asList(
|
||||||
createMax("time", 3999),
|
createMax("time", 3999),
|
||||||
createTerms("airline", new Term("c", 4, "responsetime", 31.0), new Term("b", 3, "responsetime", 32.0))))
|
createTerms("airline", new Term("c", 4, "responsetime", 31.0), new Term("b", 3, "responsetime", 32.0))))
|
||||||
|
@ -131,7 +131,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
List<Histogram.Bucket> histogramBuckets = new ArrayList<>(buckets);
|
List<Histogram.Bucket> histogramBuckets = new ArrayList<>(buckets);
|
||||||
long timestamp = 1000;
|
long timestamp = 1000;
|
||||||
for (int i = 0; i < buckets; i++) {
|
for (int i = 0; i < buckets; i++) {
|
||||||
histogramBuckets.add(createHistogramBucket(timestamp, 3, Arrays.asList(createMax("time", timestamp))));
|
histogramBuckets.add(createHistogramBucket(timestamp, 3, Collections.singletonList(createMax("time", timestamp))));
|
||||||
timestamp += 1000L;
|
timestamp += 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
extractor.setNextResponse(response);
|
extractor.setNextResponse(response);
|
||||||
|
|
||||||
assertThat(extractor.hasNext(), is(true));
|
assertThat(extractor.hasNext(), is(true));
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> extractor.next());
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, extractor::next);
|
||||||
assertThat(e.getMessage(), containsString("Top level aggregation should be [histogram]"));
|
assertThat(e.getMessage(), containsString("Top level aggregation should be [histogram]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,7 +225,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
List<Histogram.Bucket> histogramBuckets = new ArrayList<>(buckets);
|
List<Histogram.Bucket> histogramBuckets = new ArrayList<>(buckets);
|
||||||
long timestamp = 1000;
|
long timestamp = 1000;
|
||||||
for (int i = 0; i < buckets; i++) {
|
for (int i = 0; i < buckets; i++) {
|
||||||
histogramBuckets.add(createHistogramBucket(timestamp, 3, Arrays.asList(createMax("time", timestamp))));
|
histogramBuckets.add(createHistogramBucket(timestamp, 3, Collections.singletonList(createMax("time", timestamp))));
|
||||||
timestamp += 1000L;
|
timestamp += 1000L;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +253,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
extractor.setNextResponse(createErrorResponse());
|
extractor.setNextResponse(createErrorResponse());
|
||||||
|
|
||||||
assertThat(extractor.hasNext(), is(true));
|
assertThat(extractor.hasNext(), is(true));
|
||||||
expectThrows(IOException.class, () -> extractor.next());
|
expectThrows(IOException.class, extractor::next);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExtractionGivenSearchResponseHasShardFailures() throws IOException {
|
public void testExtractionGivenSearchResponseHasShardFailures() throws IOException {
|
||||||
|
@ -261,7 +261,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
extractor.setNextResponse(createResponseWithShardFailures());
|
extractor.setNextResponse(createResponseWithShardFailures());
|
||||||
|
|
||||||
assertThat(extractor.hasNext(), is(true));
|
assertThat(extractor.hasNext(), is(true));
|
||||||
IOException e = expectThrows(IOException.class, () -> extractor.next());
|
IOException e = expectThrows(IOException.class, extractor::next);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExtractionGivenInitSearchResponseEncounteredUnavailableShards() throws IOException {
|
public void testExtractionGivenInitSearchResponseEncounteredUnavailableShards() throws IOException {
|
||||||
|
@ -269,7 +269,7 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
extractor.setNextResponse(createResponseWithUnavailableShards(2));
|
extractor.setNextResponse(createResponseWithUnavailableShards(2));
|
||||||
|
|
||||||
assertThat(extractor.hasNext(), is(true));
|
assertThat(extractor.hasNext(), is(true));
|
||||||
IOException e = expectThrows(IOException.class, () -> extractor.next());
|
IOException e = expectThrows(IOException.class, extractor::next);
|
||||||
assertThat(e.getMessage(), equalTo("[" + jobId + "] Search request encountered [2] unavailable shards"));
|
assertThat(e.getMessage(), equalTo("[" + jobId + "] Search request encountered [2] unavailable shards"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,13 +277,14 @@ public class AggregationDataExtractorTests extends ESTestCase {
|
||||||
return new AggregationDataExtractorContext(jobId, timeField, indexes, types, query, aggs, start, end, true);
|
return new AggregationDataExtractorContext(jobId, timeField, indexes, types, query, aggs, start, end, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
private SearchResponse createSearchResponse(String histogramName, List<Histogram.Bucket> histogramBuckets) {
|
private SearchResponse createSearchResponse(String histogramName, List<Histogram.Bucket> histogramBuckets) {
|
||||||
Histogram histogram = mock(Histogram.class);
|
Histogram histogram = mock(Histogram.class);
|
||||||
when(histogram.getName()).thenReturn(histogramName);
|
when(histogram.getName()).thenReturn(histogramName);
|
||||||
when(histogram.getBuckets()).thenReturn(histogramBuckets);
|
when((List<Histogram.Bucket>)histogram.getBuckets()).thenReturn(histogramBuckets);
|
||||||
|
|
||||||
Aggregations searchAggs = mock(Aggregations.class);
|
Aggregations searchAggs = mock(Aggregations.class);
|
||||||
when(searchAggs.asList()).thenReturn(Arrays.asList(histogram));
|
when(searchAggs.asList()).thenReturn(Collections.singletonList(histogram));
|
||||||
return createSearchResponse(searchAggs);
|
return createSearchResponse(searchAggs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue