Skip to content

Commit 74f6e0e

Browse files
Inline redundant SingleBucketAggregation interface
This interface is just implemented once, inline it into the abstract parent of all other implementations.
1 parent f6a05c6 commit 74f6e0e

File tree

45 files changed

+334
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+334
-401
lines changed

modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/InternalChildren.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.search.aggregations.InternalAggregations;
14-
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
14+
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
1515

1616
import java.io.IOException;
1717
import java.util.Map;
1818

1919
/**
2020
* Results of the {@link ParentToChildrenAggregator}.
2121
*/
22-
public class InternalChildren extends InternalSingleBucketAggregation {
22+
public class InternalChildren extends SingleBucketAggregation {
2323
public InternalChildren(String name, long docCount, InternalAggregations aggregations, Map<String, Object> metadata) {
2424
super(name, docCount, aggregations, metadata);
2525
}
@@ -37,7 +37,7 @@ public String getWriteableName() {
3737
}
3838

3939
@Override
40-
protected InternalSingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations) {
40+
protected SingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations) {
4141
return new InternalChildren(name, docCount, subAggregations, getMetadata());
4242
}
4343
}

modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/InternalParent.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111

1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.search.aggregations.InternalAggregations;
14-
import org.elasticsearch.search.aggregations.bucket.InternalSingleBucketAggregation;
14+
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
1515

1616
import java.io.IOException;
1717
import java.util.Map;
1818

1919
/**
2020
* Results of the {@link ChildrenToParentAggregator}.
2121
*/
22-
public class InternalParent extends InternalSingleBucketAggregation {
22+
public class InternalParent extends SingleBucketAggregation {
2323
public InternalParent(String name, long docCount, InternalAggregations aggregations, Map<String, Object> metadata) {
2424
super(name, docCount, aggregations, metadata);
2525
}
@@ -37,7 +37,7 @@ public String getWriteableName() {
3737
}
3838

3939
@Override
40-
protected InternalSingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations) {
40+
protected SingleBucketAggregation newAggregation(String name, long docCount, InternalAggregations subAggregations) {
4141
return new InternalParent(name, docCount, subAggregations, getMetadata());
4242
}
4343
}

modules/parent-join/src/main/java/org/elasticsearch/join/aggregations/JoinAggregationInspectionHelper.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package org.elasticsearch.join.aggregations;
1010

11+
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
12+
1113
/**
1214
* Counterpart to {@link org.elasticsearch.search.aggregations.support.AggregationInspectionHelper}, providing
1315
* helpers for some aggs in the Join package
@@ -18,7 +20,7 @@ public static boolean hasValue(InternalParent agg) {
1820
return agg.getDocCount() > 0;
1921
}
2022

21-
public static boolean hasValue(InternalChildren agg) {
23+
public static boolean hasValue(SingleBucketAggregation agg) {
2224
return agg.getDocCount() > 0;
2325
}
2426
}

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalChildrenTests.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
import org.elasticsearch.join.ParentJoinPlugin;
1313
import org.elasticsearch.plugins.SearchPlugin;
1414
import org.elasticsearch.search.aggregations.InternalAggregations;
15-
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
15+
import org.elasticsearch.search.aggregations.SingleBucketAggregationTestCase;
16+
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
1617

1718
import java.util.List;
1819
import java.util.Map;
1920

20-
public class InternalChildrenTests extends InternalSingleBucketAggregationTestCase<InternalChildren> {
21+
public class InternalChildrenTests extends SingleBucketAggregationTestCase<SingleBucketAggregation> {
2122

2223
@Override
2324
protected SearchPlugin registerPlugin() {
2425
return new ParentJoinPlugin();
2526
}
2627

2728
@Override
28-
protected InternalChildren createTestInstance(
29+
protected SingleBucketAggregation createTestInstance(
2930
String name,
3031
long docCount,
3132
InternalAggregations aggregations,
@@ -35,7 +36,7 @@ protected InternalChildren createTestInstance(
3536
}
3637

3738
@Override
38-
protected void extraAssertReduced(InternalChildren reduced, List<InternalChildren> inputs) {
39+
protected void extraAssertReduced(SingleBucketAggregation reduced, List<SingleBucketAggregation> inputs) {
3940
// Nothing extra to assert
4041
}
4142
}

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/InternalParentTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
import org.elasticsearch.join.ParentJoinPlugin;
1313
import org.elasticsearch.plugins.SearchPlugin;
1414
import org.elasticsearch.search.aggregations.InternalAggregations;
15-
import org.elasticsearch.search.aggregations.InternalSingleBucketAggregationTestCase;
15+
import org.elasticsearch.search.aggregations.SingleBucketAggregationTestCase;
1616

1717
import java.util.List;
1818
import java.util.Map;
1919

20-
public class InternalParentTests extends InternalSingleBucketAggregationTestCase<InternalParent> {
20+
public class InternalParentTests extends SingleBucketAggregationTestCase<InternalParent> {
2121

2222
@Override
2323
protected SearchPlugin registerPlugin() {

modules/parent-join/src/test/java/org/elasticsearch/join/aggregations/ParentToChildrenAggregatorTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.elasticsearch.search.aggregations.AggregationBuilder;
3939
import org.elasticsearch.search.aggregations.Aggregator;
4040
import org.elasticsearch.search.aggregations.AggregatorTestCase;
41+
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
4142
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
4243
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
4344
import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
@@ -154,14 +155,14 @@ public void testParentChildAsSubAgg() throws IOException {
154155
StringTerms result = searchAndReduce(indexReader, new AggTestConfig(request, withJoinFields(longField("number"), kwd)));
155156

156157
StringTerms.Bucket evenBucket = result.getBucketByKey("even");
157-
InternalChildren evenChildren = evenBucket.getAggregations().get("children");
158+
SingleBucketAggregation evenChildren = evenBucket.getAggregations().get("children");
158159
Min evenMin = evenChildren.getAggregations().get("min");
159160
assertThat(evenChildren.getDocCount(), equalTo(expectedEvenChildCount));
160161
assertThat(evenMin.value(), equalTo(expectedEvenMin));
161162

162163
if (expectedOddChildCount > 0) {
163164
StringTerms.Bucket oddBucket = result.getBucketByKey("odd");
164-
InternalChildren oddChildren = oddBucket.getAggregations().get("children");
165+
SingleBucketAggregation oddChildren = oddBucket.getAggregations().get("children");
165166
Min oddMin = oddChildren.getAggregations().get("min");
166167
assertThat(oddChildren.getDocCount(), equalTo(expectedOddChildCount));
167168
assertThat(oddMin.value(), equalTo(expectedOddMin));
@@ -224,7 +225,7 @@ public void testBestDeferringCollectorWithSubAggOfChildrenAggNeedingScores() thr
224225

225226
var fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
226227
var fieldType2 = new KeywordFieldMapper.KeywordFieldType("string_field", false, true, Map.of());
227-
InternalChildren result = searchAndReduce(
228+
SingleBucketAggregation result = searchAndReduce(
228229
indexReader,
229230
new AggTestConfig(aggregationBuilder, withJoinFields(fieldType, fieldType2)).withQuery(
230231
new TermQuery(new Term("join_field", "parent_type"))
@@ -291,13 +292,13 @@ private static SortedDocValuesField createJoinField(String parentType, String id
291292
return new SortedDocValuesField("join_field#" + parentType, new BytesRef(id));
292293
}
293294

294-
private void testCase(Query query, IndexReader indexReader, Consumer<InternalChildren> verify) throws IOException {
295+
private void testCase(Query query, IndexReader indexReader, Consumer<SingleBucketAggregation> verify) throws IOException {
295296

296297
ChildrenAggregationBuilder aggregationBuilder = new ChildrenAggregationBuilder("_name", CHILD_TYPE);
297298
aggregationBuilder.subAggregation(new MinAggregationBuilder("in_child").field("number"));
298299

299300
MappedFieldType fieldType = new NumberFieldMapper.NumberFieldType("number", NumberFieldMapper.NumberType.LONG);
300-
InternalChildren result = searchAndReduce(
301+
SingleBucketAggregation result = searchAndReduce(
301302
indexReader,
302303
new AggTestConfig(aggregationBuilder, withJoinFields(fieldType)).withQuery(query)
303304
);

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/bucket/terms/StringTermsIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static class CustomScriptPlugin extends AggregationTestScriptsPlugin {
106106
protected Map<String, Function<Map<String, Object>, Object>> pluginScripts() {
107107
Map<String, Function<Map<String, Object>, Object>> scripts = super.pluginScripts();
108108

109-
scripts.put("'foo_' + _value", vars -> "foo_" + (String) vars.get("_value"));
109+
scripts.put("'foo_' + _value", vars -> "foo_" + vars.get("_value"));
110110
scripts.put("_value.substring(0,3)", vars -> ((String) vars.get("_value")).substring(0, 3));
111111

112112
scripts.put("doc['" + MULTI_VALUED_FIELD_NAME + "']", vars -> {

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/ExtendedStatsIT.java

+13-26
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.script.ScriptType;
1414
import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin;
1515
import org.elasticsearch.search.aggregations.BucketOrder;
16-
import org.elasticsearch.search.aggregations.InternalAggregation;
1716
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
1817
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
1918
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@@ -293,57 +292,45 @@ public void testSingleValuedFieldGetProperty() throws Exception {
293292
ExtendedStats stats = global.getAggregations().get("stats");
294293
assertThat(stats, notNullValue());
295294
assertThat(stats.getName(), equalTo("stats"));
296-
ExtendedStats statsFromProperty = (ExtendedStats) ((InternalAggregation) global).getProperty("stats");
295+
ExtendedStats statsFromProperty = (ExtendedStats) global.getProperty("stats");
297296
assertThat(statsFromProperty, notNullValue());
298297
assertThat(statsFromProperty, sameInstance(stats));
299298
double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
300299
assertThat(stats.getAvg(), equalTo(expectedAvgValue));
301-
assertThat((double) ((InternalAggregation) global).getProperty("stats.avg"), equalTo(expectedAvgValue));
300+
assertThat((double) global.getProperty("stats.avg"), equalTo(expectedAvgValue));
302301
double expectedMinValue = 1.0;
303302
assertThat(stats.getMin(), equalTo(expectedMinValue));
304-
assertThat((double) ((InternalAggregation) global).getProperty("stats.min"), equalTo(expectedMinValue));
303+
assertThat((double) global.getProperty("stats.min"), equalTo(expectedMinValue));
305304
double expectedMaxValue = 10.0;
306305
assertThat(stats.getMax(), equalTo(expectedMaxValue));
307-
assertThat((double) ((InternalAggregation) global).getProperty("stats.max"), equalTo(expectedMaxValue));
306+
assertThat((double) global.getProperty("stats.max"), equalTo(expectedMaxValue));
308307
double expectedSumValue = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
309308
assertThat(stats.getSum(), equalTo(expectedSumValue));
310-
assertThat((double) ((InternalAggregation) global).getProperty("stats.sum"), equalTo(expectedSumValue));
309+
assertThat((double) global.getProperty("stats.sum"), equalTo(expectedSumValue));
311310
long expectedCountValue = 10;
312311
assertThat(stats.getCount(), equalTo(expectedCountValue));
313-
assertThat((double) ((InternalAggregation) global).getProperty("stats.count"), equalTo((double) expectedCountValue));
312+
assertThat((double) global.getProperty("stats.count"), equalTo((double) expectedCountValue));
314313
double expectedSumOfSquaresValue = (double) 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 + 81 + 100;
315314
assertThat(stats.getSumOfSquares(), equalTo(expectedSumOfSquaresValue));
316-
assertThat((double) ((InternalAggregation) global).getProperty("stats.sum_of_squares"), equalTo(expectedSumOfSquaresValue));
315+
assertThat((double) global.getProperty("stats.sum_of_squares"), equalTo(expectedSumOfSquaresValue));
317316
double expectedVarianceValue = variance(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
318317
assertThat(stats.getVariance(), equalTo(expectedVarianceValue));
319-
assertThat((double) ((InternalAggregation) global).getProperty("stats.variance"), equalTo(expectedVarianceValue));
318+
assertThat((double) global.getProperty("stats.variance"), equalTo(expectedVarianceValue));
320319
double expectedVariancePopulationValue = variancePopulation(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
321320
assertThat(stats.getVariancePopulation(), equalTo(expectedVariancePopulationValue));
322-
assertThat(
323-
(double) ((InternalAggregation) global).getProperty("stats.variance_population"),
324-
equalTo(expectedVariancePopulationValue)
325-
);
321+
assertThat((double) global.getProperty("stats.variance_population"), equalTo(expectedVariancePopulationValue));
326322
double expectedVarianceSamplingValue = varianceSampling(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
327323
assertThat(stats.getVarianceSampling(), equalTo(expectedVarianceSamplingValue));
328-
assertThat(
329-
(double) ((InternalAggregation) global).getProperty("stats.variance_sampling"),
330-
equalTo(expectedVarianceSamplingValue)
331-
);
324+
assertThat((double) global.getProperty("stats.variance_sampling"), equalTo(expectedVarianceSamplingValue));
332325
double expectedStdDevValue = stdDev(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
333326
assertThat(stats.getStdDeviation(), equalTo(expectedStdDevValue));
334-
assertThat((double) ((InternalAggregation) global).getProperty("stats.std_deviation"), equalTo(expectedStdDevValue));
327+
assertThat((double) global.getProperty("stats.std_deviation"), equalTo(expectedStdDevValue));
335328
double expectedStdDevPopulationValue = stdDevPopulation(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
336329
assertThat(stats.getStdDeviationPopulation(), equalTo(expectedStdDevValue));
337-
assertThat(
338-
(double) ((InternalAggregation) global).getProperty("stats.std_deviation_population"),
339-
equalTo(expectedStdDevPopulationValue)
340-
);
330+
assertThat((double) global.getProperty("stats.std_deviation_population"), equalTo(expectedStdDevPopulationValue));
341331
double expectedStdDevSamplingValue = stdDevSampling(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
342332
assertThat(stats.getStdDeviationSampling(), equalTo(expectedStdDevSamplingValue));
343-
assertThat(
344-
(double) ((InternalAggregation) global).getProperty("stats.std_deviation_sampling"),
345-
equalTo(expectedStdDevSamplingValue)
346-
);
333+
assertThat((double) global.getProperty("stats.std_deviation_sampling"), equalTo(expectedStdDevSamplingValue));
347334
}
348335
);
349336
}

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/HDRPercentileRanksIT.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.elasticsearch.script.ScriptType;
1515
import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin;
1616
import org.elasticsearch.search.aggregations.BucketOrder;
17-
import org.elasticsearch.search.aggregations.InternalAggregation;
1817
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
1918
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
2019
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@@ -226,7 +225,7 @@ public void testSingleValuedFieldGetProperty() throws Exception {
226225
PercentileRanks values = global.getAggregations().get("percentile_ranks");
227226
assertThat(values, notNullValue());
228227
assertThat(values.getName(), equalTo("percentile_ranks"));
229-
assertThat(((InternalAggregation) global).getProperty("percentile_ranks"), sameInstance(values));
228+
assertThat(global.getProperty("percentile_ranks"), sameInstance(values));
230229
}
231230
);
232231
}

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/HDRPercentilesIT.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.script.ScriptType;
1616
import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin;
1717
import org.elasticsearch.search.aggregations.BucketOrder;
18-
import org.elasticsearch.search.aggregations.InternalAggregation;
1918
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
2019
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
2120
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
@@ -203,7 +202,7 @@ public void testSingleValuedFieldGetProperty() throws Exception {
203202
Percentiles percentiles = global.getAggregations().get("percentiles");
204203
assertThat(percentiles, notNullValue());
205204
assertThat(percentiles.getName(), equalTo("percentiles"));
206-
assertThat(((InternalAggregation) global).getProperty("percentiles"), sameInstance(percentiles));
205+
assertThat(global.getProperty("percentiles"), sameInstance(percentiles));
207206
}
208207
);
209208
}

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/MedianAbsoluteDeviationIT.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.script.ScriptType;
1616
import org.elasticsearch.search.aggregations.AggregationTestScriptsPlugin;
1717
import org.elasticsearch.search.aggregations.BucketOrder;
18-
import org.elasticsearch.search.aggregations.InternalAggregation;
1918
import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation;
2019
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
2120
import org.elasticsearch.search.aggregations.bucket.range.Range;
@@ -189,7 +188,7 @@ public void testSingleValuedFieldGetProperty() throws Exception {
189188
final MedianAbsoluteDeviation mad = global.getAggregations().get("mad");
190189
assertThat(mad, notNullValue());
191190
assertThat(mad.getName(), is("mad"));
192-
assertThat(((InternalAggregation) global).getProperty("mad"), sameInstance(mad));
191+
assertThat(global.getProperty("mad"), sameInstance(mad));
193192
}
194193
);
195194
}

server/src/internalClusterTest/java/org/elasticsearch/search/aggregations/metrics/ScriptedMetricIT.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,8 @@ public void testInitMapCombineReduceGetProperty() throws Exception {
731731
assertThat(object, notNullValue());
732732
assertThat(object, instanceOf(Number.class));
733733
assertThat(((Number) object).longValue(), equalTo(numDocs * 3));
734-
assertThat(((InternalAggregation) global).getProperty("scripted"), sameInstance(scriptedMetricAggregation));
735-
assertThat((List) ((InternalAggregation) global).getProperty("scripted.value"), sameInstance(aggregationList));
734+
assertThat(global.getProperty("scripted"), sameInstance(scriptedMetricAggregation));
735+
assertThat((List) global.getProperty("scripted.value"), sameInstance(aggregationList));
736736
assertThat((List) ((InternalAggregation) scriptedMetricAggregation).getProperty("value"), sameInstance(aggregationList));
737737
}
738738
);

0 commit comments

Comments
 (0)