Skip to content

Commit 2ba3024

Browse files
committed
Remove generic on AggregatorFactory (elastic#43664)
AggregatorFactory was generic over itself, but it doesn't appear we use this functionality anywhere (e.g. to allow the super class to declare arguments/return types generically for subclasses to override). Most places use a wildcard constraint, and even when a concrete type is specified it wasn't used. But since AggFactories are widely used, this led to the generic touching many pieces of code and making type signatures fairly complex
1 parent 4390d4a commit 2ba3024

File tree

114 files changed

+235
-221
lines changed

Some content is hidden

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

114 files changed

+235
-221
lines changed

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public MultiValueMode multiValueMode() {
8181

8282
@Override
8383
protected MatrixStatsAggregatorFactory innerBuild(SearchContext context, Map<String, ValuesSourceConfig<Numeric>> configs,
84-
AggregatorFactory<?> parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
84+
AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
8585
return new MatrixStatsAggregatorFactory(name, configs, multiValueMode, context, parent, subFactoriesBuilder, metaData);
8686
}
8787

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/MatrixStatsAggregatorFactory.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,13 @@
3232
import java.util.List;
3333
import java.util.Map;
3434

35-
final class MatrixStatsAggregatorFactory
36-
extends ArrayValuesSourceAggregatorFactory<ValuesSource.Numeric, MatrixStatsAggregatorFactory> {
35+
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory<ValuesSource.Numeric> {
3736

3837
private final MultiValueMode multiValueMode;
3938

4039
MatrixStatsAggregatorFactory(String name,
4140
Map<String, ValuesSourceConfig<ValuesSource.Numeric>> configs, MultiValueMode multiValueMode,
42-
SearchContext context, AggregatorFactory<?> parent, AggregatorFactories.Builder subFactoriesBuilder,
41+
SearchContext context, AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder,
4342
Map<String, Object> metaData) throws IOException {
4443
super(name, configs, context, parent, subFactoriesBuilder, metaData);
4544
this.multiValueMode = multiValueMode;

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregationBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ public Map<String, Object> missingMap() {
239239
}
240240

241241
@Override
242-
protected final ArrayValuesSourceAggregatorFactory<VS, ?> doBuild(SearchContext context, AggregatorFactory<?> parent,
242+
protected final ArrayValuesSourceAggregatorFactory<VS> doBuild(SearchContext context, AggregatorFactory parent,
243243
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
244244
Map<String, ValuesSourceConfig<VS>> configs = resolveConfig(context);
245-
ArrayValuesSourceAggregatorFactory<VS, ?> factory = innerBuild(context, configs, parent, subFactoriesBuilder);
245+
ArrayValuesSourceAggregatorFactory<VS> factory = innerBuild(context, configs, parent, subFactoriesBuilder);
246246
return factory;
247247
}
248248

@@ -255,9 +255,9 @@ protected Map<String, ValuesSourceConfig<VS>> resolveConfig(SearchContext contex
255255
return configs;
256256
}
257257

258-
protected abstract ArrayValuesSourceAggregatorFactory<VS, ?> innerBuild(SearchContext context,
258+
protected abstract ArrayValuesSourceAggregatorFactory<VS> innerBuild(SearchContext context,
259259
Map<String, ValuesSourceConfig<VS>> configs,
260-
AggregatorFactory<?> parent,
260+
AggregatorFactory parent,
261261
AggregatorFactories.Builder subFactoriesBuilder) throws IOException;
262262

263263
public ValuesSourceConfig<VS> config(SearchContext context, String field, Script script) {

modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/support/ArrayValuesSourceAggregatorFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import java.util.List;
3131
import java.util.Map;
3232

33-
public abstract class ArrayValuesSourceAggregatorFactory<VS extends ValuesSource, AF extends ArrayValuesSourceAggregatorFactory<VS, AF>>
34-
extends AggregatorFactory<AF> {
33+
public abstract class ArrayValuesSourceAggregatorFactory<VS extends ValuesSource>
34+
extends AggregatorFactory {
3535

3636
protected Map<String, ValuesSourceConfig<VS>> configs;
3737

3838
public ArrayValuesSourceAggregatorFactory(String name, Map<String, ValuesSourceConfig<VS>> configs,
39-
SearchContext context, AggregatorFactory<?> parent,
39+
SearchContext context, AggregatorFactory parent,
4040
AggregatorFactories.Builder subFactoriesBuilder,
4141
Map<String, Object> metaData) throws IOException {
4242
super(name, context, parent, subFactoriesBuilder, metaData);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
9595
}
9696

9797
@Override
98-
protected ValuesSourceAggregatorFactory<WithOrdinals, ?> innerBuild(SearchContext context,
98+
protected ValuesSourceAggregatorFactory<WithOrdinals> innerBuild(SearchContext context,
9999
ValuesSourceConfig<WithOrdinals> config,
100-
AggregatorFactory<?> parent,
100+
AggregatorFactory parent,
101101
Builder subFactoriesBuilder) throws IOException {
102102
return new ChildrenAggregatorFactory(name, config, childFilter, parentFilter, context, parent,
103103
subFactoriesBuilder, metaData);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.util.List;
3636
import java.util.Map;
3737

38-
public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals, ChildrenAggregatorFactory> {
38+
public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals> {
3939

4040
private final Query parentFilter;
4141
private final Query childFilter;
@@ -45,7 +45,7 @@ public ChildrenAggregatorFactory(String name,
4545
Query childFilter,
4646
Query parentFilter,
4747
SearchContext context,
48-
AggregatorFactory<?> parent,
48+
AggregatorFactory parent,
4949
AggregatorFactories.Builder subFactoriesBuilder,
5050
Map<String, Object> metaData) throws IOException {
5151
super(name, config, context, parent, subFactoriesBuilder, metaData);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
9595
}
9696

9797
@Override
98-
protected ValuesSourceAggregatorFactory<WithOrdinals, ?> innerBuild(SearchContext context,
98+
protected ValuesSourceAggregatorFactory<WithOrdinals> innerBuild(SearchContext context,
9999
ValuesSourceConfig<WithOrdinals> config,
100-
AggregatorFactory<?> parent,
100+
AggregatorFactory parent,
101101
Builder subFactoriesBuilder) throws IOException {
102102
return new ParentAggregatorFactory(name, config, childFilter, parentFilter, context, parent,
103103
subFactoriesBuilder, metaData);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import java.util.List;
3636
import java.util.Map;
3737

38-
public class ParentAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals, ParentAggregatorFactory> {
38+
public class ParentAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals> {
3939

4040
private final Query parentFilter;
4141
private final Query childFilter;
@@ -45,7 +45,7 @@ public ParentAggregatorFactory(String name,
4545
Query childFilter,
4646
Query parentFilter,
4747
SearchContext context,
48-
AggregatorFactory<?> parent,
48+
AggregatorFactory parent,
4949
AggregatorFactories.Builder subFactoriesBuilder,
5050
Map<String, Object> metaData) throws IOException {
5151
super(name, config, context, parent, subFactoriesBuilder, metaData);

server/src/main/java/org/elasticsearch/search/aggregations/AbstractAggregationBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ public final String getWriteableName() {
135135
}
136136

137137
@Override
138-
public final AggregatorFactory<?> build(SearchContext context, AggregatorFactory<?> parent) throws IOException {
139-
AggregatorFactory<?> factory = doBuild(context, parent, factoriesBuilder);
138+
public final AggregatorFactory build(SearchContext context, AggregatorFactory parent) throws IOException {
139+
AggregatorFactory factory = doBuild(context, parent, factoriesBuilder);
140140
return factory;
141141
}
142142

143-
protected abstract AggregatorFactory<?> doBuild(SearchContext context, AggregatorFactory<?> parent,
143+
protected abstract AggregatorFactory doBuild(SearchContext context, AggregatorFactory parent,
144144
AggregatorFactories.Builder subfactoriesBuilder) throws IOException;
145145

146146
@Override

server/src/main/java/org/elasticsearch/search/aggregations/AggregationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public String getName() {
6363
}
6464

6565
/** Internal: build an {@link AggregatorFactory} based on the configuration of this builder. */
66-
protected abstract AggregatorFactory<?> build(SearchContext context, AggregatorFactory<?> parent) throws IOException;
66+
protected abstract AggregatorFactory build(SearchContext context, AggregatorFactory parent) throws IOException;
6767

6868
/** Associate metadata with this {@link AggregationBuilder}. */
6969
@Override

server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,16 @@ public AggParseContext(String name) {
161161
}
162162
}
163163

164-
public static final AggregatorFactories EMPTY = new AggregatorFactories(new AggregatorFactory<?>[0], new ArrayList<>());
164+
public static final AggregatorFactories EMPTY = new AggregatorFactories(new AggregatorFactory[0], new ArrayList<>());
165165

166-
private AggregatorFactory<?>[] factories;
166+
private AggregatorFactory[] factories;
167167
private List<PipelineAggregationBuilder> pipelineAggregatorFactories;
168168

169169
public static Builder builder() {
170170
return new Builder();
171171
}
172172

173-
private AggregatorFactories(AggregatorFactory<?>[] factories, List<PipelineAggregationBuilder> pipelineAggregators) {
173+
private AggregatorFactories(AggregatorFactory[] factories, List<PipelineAggregationBuilder> pipelineAggregators) {
174174
this.factories = factories;
175175
this.pipelineAggregatorFactories = pipelineAggregators;
176176
}
@@ -314,7 +314,7 @@ Builder skipResolveOrder() {
314314
return this;
315315
}
316316

317-
public AggregatorFactories build(SearchContext context, AggregatorFactory<?> parent) throws IOException {
317+
public AggregatorFactories build(SearchContext context, AggregatorFactory parent) throws IOException {
318318
if (aggregationBuilders.isEmpty() && pipelineAggregatorBuilders.isEmpty()) {
319319
return EMPTY;
320320
}
@@ -325,7 +325,7 @@ public AggregatorFactories build(SearchContext context, AggregatorFactory<?> par
325325
orderedpipelineAggregators = resolvePipelineAggregatorOrder(this.pipelineAggregatorBuilders, this.aggregationBuilders,
326326
parent);
327327
}
328-
AggregatorFactory<?>[] aggFactories = new AggregatorFactory<?>[aggregationBuilders.size()];
328+
AggregatorFactory[] aggFactories = new AggregatorFactory[aggregationBuilders.size()];
329329

330330
int i = 0;
331331
for (AggregationBuilder agg : aggregationBuilders) {
@@ -337,7 +337,7 @@ public AggregatorFactories build(SearchContext context, AggregatorFactory<?> par
337337

338338
private List<PipelineAggregationBuilder> resolvePipelineAggregatorOrder(
339339
Collection<PipelineAggregationBuilder> pipelineAggregatorBuilders, Collection<AggregationBuilder> aggregationBuilders,
340-
AggregatorFactory<?> parent) {
340+
AggregatorFactory parent) {
341341
Map<String, PipelineAggregationBuilder> pipelineAggregatorBuildersMap = new HashMap<>();
342342
for (PipelineAggregationBuilder builder : pipelineAggregatorBuilders) {
343343
pipelineAggregatorBuildersMap.put(builder.getName(), builder);

server/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactory.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@
3333
import java.util.List;
3434
import java.util.Map;
3535

36-
public abstract class AggregatorFactory<AF extends AggregatorFactory<AF>> {
36+
public abstract class AggregatorFactory {
3737

3838
public static final class MultiBucketAggregatorWrapper extends Aggregator {
3939
private final BigArrays bigArrays;
4040
private final Aggregator parent;
41-
private final AggregatorFactory<?> factory;
41+
private final AggregatorFactory factory;
4242
private final Aggregator first;
4343
ObjectArray<Aggregator> aggregators;
4444
ObjectArray<LeafBucketCollector> collectors;
4545

46-
MultiBucketAggregatorWrapper(BigArrays bigArrays, SearchContext context, Aggregator parent, AggregatorFactory<?> factory,
46+
MultiBucketAggregatorWrapper(BigArrays bigArrays, SearchContext context, Aggregator parent, AggregatorFactory factory,
4747
Aggregator first) {
4848
this.bigArrays = bigArrays;
4949
this.parent = parent;
@@ -167,7 +167,7 @@ public void close() {
167167
}
168168

169169
protected final String name;
170-
protected final AggregatorFactory<?> parent;
170+
protected final AggregatorFactory parent;
171171
protected final AggregatorFactories factories;
172172
protected final Map<String, Object> metaData;
173173
protected final SearchContext context;
@@ -180,7 +180,7 @@ public void close() {
180180
* @throws IOException
181181
* if an error occurs creating the factory
182182
*/
183-
public AggregatorFactory(String name, SearchContext context, AggregatorFactory<?> parent,
183+
public AggregatorFactory(String name, SearchContext context, AggregatorFactory parent,
184184
AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData) throws IOException {
185185
this.name = name;
186186
this.context = context;
@@ -217,7 +217,7 @@ public final Aggregator create(Aggregator parent, boolean collectsFromSingleBuck
217217
return createInternal(parent, collectsFromSingleBucket, this.factories.createPipelineAggregators(), this.metaData);
218218
}
219219

220-
public AggregatorFactory<?> getParent() {
220+
public AggregatorFactory getParent() {
221221
return parent;
222222
}
223223

@@ -226,7 +226,7 @@ public AggregatorFactory<?> getParent() {
226226
* {@link Aggregator}s that only know how to collect bucket {@code 0}, this
227227
* returns an aggregator that can collect any bucket.
228228
*/
229-
protected static Aggregator asMultiBucketAggregator(final AggregatorFactory<?> factory, final SearchContext context,
229+
protected static Aggregator asMultiBucketAggregator(final AggregatorFactory factory, final SearchContext context,
230230
final Aggregator parent) throws IOException {
231231
final Aggregator first = factory.create(parent, true);
232232
final BigArrays bigArrays = context.bigArrays();

server/src/main/java/org/elasticsearch/search/aggregations/PipelineAggregationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public final String[] getBucketsPaths() {
6767
* Internal: Validates the state of this factory (makes sure the factory is properly
6868
* configured)
6969
*/
70-
protected abstract void validate(AggregatorFactory<?> parent, Collection<AggregationBuilder> aggregationBuilders,
70+
protected abstract void validate(AggregatorFactory parent, Collection<AggregationBuilder> aggregationBuilders,
7171
Collection<PipelineAggregationBuilder> pipelineAggregatorBuilders);
7272

7373
/**

server/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public Map<String, QueryBuilder> filters() {
196196

197197

198198
@Override
199-
protected AggregatorFactory<?> doBuild(SearchContext context, AggregatorFactory<?> parent, Builder subFactoriesBuilder)
199+
protected AggregatorFactory doBuild(SearchContext context, AggregatorFactory parent, Builder subFactoriesBuilder)
200200
throws IOException {
201201
int maxFilters = context.indexShard().indexSettings().getMaxAdjacencyMatrixFilters();
202202
if (filters.size() > maxFilters){

server/src/main/java/org/elasticsearch/search/aggregations/bucket/adjacency/AdjacencyMatrixAggregatorFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434
import java.util.List;
3535
import java.util.Map;
3636

37-
public class AdjacencyMatrixAggregatorFactory extends AggregatorFactory<AdjacencyMatrixAggregatorFactory> {
37+
public class AdjacencyMatrixAggregatorFactory extends AggregatorFactory {
3838

3939
private final String[] keys;
4040
private final Weight[] weights;
4141
private final String separator;
4242

4343
public AdjacencyMatrixAggregatorFactory(String name, List<KeyedFilter> filters, String separator,
44-
SearchContext context, AggregatorFactory<?> parent, AggregatorFactories.Builder subFactories,
44+
SearchContext context, AggregatorFactory parent, AggregatorFactories.Builder subFactories,
4545
Map<String, Object> metaData) throws IOException {
4646
super(name, context, parent, subFactories, metaData);
4747
IndexSearcher contextSearcher = context.searcher();

server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public int size() {
162162
* this aggregator or the instance of the parent's factory that is incompatible with
163163
* the composite aggregation.
164164
*/
165-
private AggregatorFactory<?> checkParentIsNullOrNested(AggregatorFactory<?> factory) {
165+
private AggregatorFactory checkParentIsNullOrNested(AggregatorFactory factory) {
166166
if (factory == null) {
167167
return null;
168168
} else if (factory instanceof NestedAggregatorFactory) {
@@ -195,9 +195,9 @@ private static void validateSources(List<CompositeValuesSourceBuilder<?>> source
195195
}
196196

197197
@Override
198-
protected AggregatorFactory<?> doBuild(SearchContext context, AggregatorFactory<?> parent,
198+
protected AggregatorFactory doBuild(SearchContext context, AggregatorFactory parent,
199199
AggregatorFactories.Builder subfactoriesBuilder) throws IOException {
200-
AggregatorFactory<?> invalid = checkParentIsNullOrNested(parent);
200+
AggregatorFactory invalid = checkParentIsNullOrNested(parent);
201201
if (invalid != null) {
202202
throw new IllegalArgumentException("[composite] aggregation cannot be used with a parent aggregation of" +
203203
" type: [" + invalid.getClass().getSimpleName() + "]");

server/src/main/java/org/elasticsearch/search/aggregations/bucket/composite/CompositeAggregationFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import java.util.List;
3030
import java.util.Map;
3131

32-
class CompositeAggregationFactory extends AggregatorFactory<CompositeAggregationFactory> {
32+
class CompositeAggregationFactory extends AggregatorFactory {
3333
private final int size;
3434
private final CompositeValuesSourceConfig[] sources;
3535
private final CompositeKey afterKey;
3636

37-
CompositeAggregationFactory(String name, SearchContext context, AggregatorFactory<?> parent,
37+
CompositeAggregationFactory(String name, SearchContext context, AggregatorFactory parent,
3838
AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData,
3939
int size, CompositeValuesSourceConfig[] sources, CompositeKey afterKey) throws IOException {
4040
super(name, context, parent, subFactoriesBuilder, metaData);

server/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected AggregationBuilder doRewrite(QueryRewriteContext queryShardContext) th
9393
}
9494

9595
@Override
96-
protected AggregatorFactory<?> doBuild(SearchContext context, AggregatorFactory<?> parent,
96+
protected AggregatorFactory doBuild(SearchContext context, AggregatorFactory parent,
9797
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
9898
return new FilterAggregatorFactory(name, filter, context, parent, subFactoriesBuilder, metaData);
9999
}

server/src/main/java/org/elasticsearch/search/aggregations/bucket/filter/FilterAggregatorFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@
3535
import java.util.List;
3636
import java.util.Map;
3737

38-
public class FilterAggregatorFactory extends AggregatorFactory<FilterAggregatorFactory> {
38+
public class FilterAggregatorFactory extends AggregatorFactory {
3939

4040
private Weight weight;
4141
private Query filter;
4242

4343
public FilterAggregatorFactory(String name, QueryBuilder filterBuilder, SearchContext context,
44-
AggregatorFactory<?> parent, AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData) throws IOException {
44+
AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder, Map<String, Object> metaData) throws IOException {
4545
super(name, context, parent, subFactoriesBuilder, metaData);
4646
filter = filterBuilder.toQuery(context.getQueryShardContext());
4747
}

0 commit comments

Comments
 (0)