Skip to content

Commit 60b7ae7

Browse files
authored
Remove generics from ValuesSource related classes (#49606)
1 parent 0331312 commit 60b7ae7

File tree

96 files changed

+517
-413
lines changed

Some content is hidden

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

96 files changed

+517
-413
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
3232
import org.elasticsearch.search.aggregations.support.ValueType;
3333
import org.elasticsearch.search.aggregations.support.ValuesSource;
34-
import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
3534
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
3635

3736
import java.io.IOException;
@@ -81,7 +80,7 @@ public MultiValueMode multiValueMode() {
8180

8281
@Override
8382
protected MatrixStatsAggregatorFactory innerBuild(QueryShardContext queryShardContext,
84-
Map<String, ValuesSourceConfig<Numeric>> configs,
83+
Map<String, ValuesSourceConfig> configs,
8584
AggregatorFactory parent,
8685
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
8786
return new MatrixStatsAggregatorFactory(name, configs, multiValueMode, queryShardContext, parent, subFactoriesBuilder, metaData);

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.elasticsearch.index.query.QueryShardContext;
2222
import org.elasticsearch.search.MultiValueMode;
23+
import org.elasticsearch.search.aggregations.AggregationExecutionException;
2324
import org.elasticsearch.search.aggregations.Aggregator;
2425
import org.elasticsearch.search.aggregations.AggregatorFactories;
2526
import org.elasticsearch.search.aggregations.AggregatorFactory;
@@ -30,15 +31,16 @@
3031
import org.elasticsearch.search.internal.SearchContext;
3132

3233
import java.io.IOException;
34+
import java.util.HashMap;
3335
import java.util.List;
3436
import java.util.Map;
3537

36-
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory<ValuesSource.Numeric> {
38+
final class MatrixStatsAggregatorFactory extends ArrayValuesSourceAggregatorFactory {
3739

3840
private final MultiValueMode multiValueMode;
3941

4042
MatrixStatsAggregatorFactory(String name,
41-
Map<String, ValuesSourceConfig<ValuesSource.Numeric>> configs,
43+
Map<String, ValuesSourceConfig> configs,
4244
MultiValueMode multiValueMode,
4345
QueryShardContext queryShardContext,
4446
AggregatorFactory parent,
@@ -58,12 +60,21 @@ protected Aggregator createUnmapped(SearchContext searchContext,
5860
}
5961

6062
@Override
61-
protected Aggregator doCreateInternal(Map<String, ValuesSource.Numeric> valuesSources,
63+
protected Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
6264
SearchContext searchContext,
6365
Aggregator parent,
6466
boolean collectsFromSingleBucket,
6567
List<PipelineAggregator> pipelineAggregators,
6668
Map<String, Object> metaData) throws IOException {
67-
return new MatrixStatsAggregator(name, valuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
69+
Map<String, ValuesSource.Numeric> typedValuesSources = new HashMap<>(valuesSources.size());
70+
for (Map.Entry<String, ValuesSource> entry : valuesSources.entrySet()) {
71+
if (entry.getValue() instanceof ValuesSource.Numeric == false) {
72+
throw new AggregationExecutionException("ValuesSource type " + entry.getValue().toString() +
73+
"is not supported for aggregation " + this.name());
74+
}
75+
// TODO: There must be a better option than this.
76+
typedValuesSources.put(entry.getKey(), (ValuesSource.Numeric) entry.getValue());
77+
}
78+
return new MatrixStatsAggregator(name, typedValuesSources, searchContext, parent, multiValueMode, pipelineAggregators, metaData);
6879
}
6980
}

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

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

241241
@Override
242-
protected final ArrayValuesSourceAggregatorFactory<VS> doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
243-
Builder subFactoriesBuilder) throws IOException {
244-
Map<String, ValuesSourceConfig<VS>> configs = resolveConfig(queryShardContext);
245-
ArrayValuesSourceAggregatorFactory<VS> factory = innerBuild(queryShardContext, configs, parent, subFactoriesBuilder);
242+
protected final ArrayValuesSourceAggregatorFactory doBuild(QueryShardContext queryShardContext, AggregatorFactory parent,
243+
Builder subFactoriesBuilder) throws IOException {
244+
Map<String, ValuesSourceConfig> configs = resolveConfig(queryShardContext);
245+
ArrayValuesSourceAggregatorFactory factory = innerBuild(queryShardContext, configs, parent, subFactoriesBuilder);
246246
return factory;
247247
}
248248

249-
protected Map<String, ValuesSourceConfig<VS>> resolveConfig(QueryShardContext queryShardContext) {
250-
HashMap<String, ValuesSourceConfig<VS>> configs = new HashMap<>();
249+
protected Map<String, ValuesSourceConfig> resolveConfig(QueryShardContext queryShardContext) {
250+
HashMap<String, ValuesSourceConfig> configs = new HashMap<>();
251251
for (String field : fields) {
252-
ValuesSourceConfig<VS> config = config(queryShardContext, field, null);
252+
ValuesSourceConfig config = config(queryShardContext, field, null);
253253
configs.put(field, config);
254254
}
255255
return configs;
256256
}
257257

258-
protected abstract ArrayValuesSourceAggregatorFactory<VS> innerBuild(QueryShardContext queryShardContext,
259-
Map<String, ValuesSourceConfig<VS>> configs,
260-
AggregatorFactory parent,
261-
AggregatorFactories.Builder subFactoriesBuilder) throws IOException;
258+
protected abstract ArrayValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
259+
Map<String, ValuesSourceConfig> configs,
260+
AggregatorFactory parent,
261+
AggregatorFactories.Builder subFactoriesBuilder) throws IOException;
262262

263-
public ValuesSourceConfig<VS> config(QueryShardContext queryShardContext, String field, Script script) {
263+
public ValuesSourceConfig config(QueryShardContext queryShardContext, String field, Script script) {
264264

265265
ValueType valueType = this.valueType != null ? this.valueType : targetValueType;
266266

267267
if (field == null) {
268268
if (script == null) {
269-
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(CoreValuesSourceType.ANY);
269+
ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.ANY);
270270
return config.format(resolveFormat(null, valueType));
271271
}
272272
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
@@ -277,33 +277,33 @@ public ValuesSourceConfig<VS> config(QueryShardContext queryShardContext, String
277277
// on Bytes
278278
valuesSourceType = CoreValuesSourceType.BYTES;
279279
}
280-
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
280+
ValuesSourceConfig config = new ValuesSourceConfig(valuesSourceType);
281281
config.missing(missingMap.get(field));
282282
return config.format(resolveFormat(format, valueType));
283283
}
284284

285285
MappedFieldType fieldType = queryShardContext.getMapperService().fullName(field);
286286
if (fieldType == null) {
287287
ValuesSourceType valuesSourceType = valueType != null ? valueType.getValuesSourceType() : this.valuesSourceType;
288-
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
288+
ValuesSourceConfig config = new ValuesSourceConfig(valuesSourceType);
289289
config.missing(missingMap.get(field));
290290
config.format(resolveFormat(format, valueType));
291291
return config.unmapped(true);
292292
}
293293

294294
IndexFieldData<?> indexFieldData = queryShardContext.getForField(fieldType);
295295

296-
ValuesSourceConfig<VS> config;
296+
ValuesSourceConfig config;
297297
if (valuesSourceType == CoreValuesSourceType.ANY) {
298298
if (indexFieldData instanceof IndexNumericFieldData) {
299-
config = new ValuesSourceConfig<>(CoreValuesSourceType.NUMERIC);
299+
config = new ValuesSourceConfig(CoreValuesSourceType.NUMERIC);
300300
} else if (indexFieldData instanceof IndexGeoPointFieldData) {
301-
config = new ValuesSourceConfig<>(CoreValuesSourceType.GEOPOINT);
301+
config = new ValuesSourceConfig(CoreValuesSourceType.GEOPOINT);
302302
} else {
303-
config = new ValuesSourceConfig<>(CoreValuesSourceType.BYTES);
303+
config = new ValuesSourceConfig(CoreValuesSourceType.BYTES);
304304
}
305305
} else {
306-
config = new ValuesSourceConfig<>(valuesSourceType);
306+
config = new ValuesSourceConfig(valuesSourceType);
307307
}
308308

309309
config.fieldContext(new FieldContext(field, indexFieldData, fieldType));

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
import java.util.List;
3232
import java.util.Map;
3333

34-
public abstract class ArrayValuesSourceAggregatorFactory<VS extends ValuesSource>
34+
public abstract class ArrayValuesSourceAggregatorFactory
3535
extends AggregatorFactory {
3636

37-
protected Map<String, ValuesSourceConfig<VS>> configs;
37+
protected Map<String, ValuesSourceConfig> configs;
3838

39-
public ArrayValuesSourceAggregatorFactory(String name, Map<String, ValuesSourceConfig<VS>> configs,
39+
public ArrayValuesSourceAggregatorFactory(String name, Map<String, ValuesSourceConfig> configs,
4040
QueryShardContext queryShardContext, AggregatorFactory parent,
4141
AggregatorFactories.Builder subFactoriesBuilder,
4242
Map<String, Object> metaData) throws IOException {
@@ -50,10 +50,10 @@ public Aggregator createInternal(SearchContext searchContext,
5050
boolean collectsFromSingleBucket,
5151
List<PipelineAggregator> pipelineAggregators,
5252
Map<String, Object> metaData) throws IOException {
53-
HashMap<String, VS> valuesSources = new HashMap<>();
53+
HashMap<String, ValuesSource> valuesSources = new HashMap<>();
5454

55-
for (Map.Entry<String, ValuesSourceConfig<VS>> config : configs.entrySet()) {
56-
VS vs = config.getValue().toValuesSource(queryShardContext);
55+
for (Map.Entry<String, ValuesSourceConfig> config : configs.entrySet()) {
56+
ValuesSource vs = config.getValue().toValuesSource(queryShardContext);
5757
if (vs != null) {
5858
valuesSources.put(config.getKey(), vs);
5959
}
@@ -70,7 +70,7 @@ protected abstract Aggregator createUnmapped(SearchContext searchContext,
7070
List<PipelineAggregator> pipelineAggregators,
7171
Map<String, Object> metaData) throws IOException;
7272

73-
protected abstract Aggregator doCreateInternal(Map<String, VS> valuesSources,
73+
protected abstract Aggregator doCreateInternal(Map<String, ValuesSource> valuesSources,
7474
SearchContext searchContext,
7575
Aggregator parent,
7676
boolean collectsFromSingleBucket,

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.elasticsearch.search.aggregations.support.CoreValuesSourceType;
3737
import org.elasticsearch.search.aggregations.support.FieldContext;
3838
import org.elasticsearch.search.aggregations.support.ValueType;
39-
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals;
4039
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
4140
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
4241
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
@@ -46,7 +45,7 @@
4645
import java.util.Objects;
4746

4847
public class ChildrenAggregationBuilder
49-
extends ValuesSourceAggregationBuilder<WithOrdinals, ChildrenAggregationBuilder> {
48+
extends ValuesSourceAggregationBuilder<ChildrenAggregationBuilder> {
5049

5150
public static final String NAME = "children";
5251

@@ -95,22 +94,22 @@ protected void innerWriteTo(StreamOutput out) throws IOException {
9594
}
9695

9796
@Override
98-
protected ValuesSourceAggregatorFactory<WithOrdinals> innerBuild(QueryShardContext queryShardContext,
99-
ValuesSourceConfig<WithOrdinals> config,
100-
AggregatorFactory parent,
101-
Builder subFactoriesBuilder) throws IOException {
97+
protected ValuesSourceAggregatorFactory innerBuild(QueryShardContext queryShardContext,
98+
ValuesSourceConfig config,
99+
AggregatorFactory parent,
100+
Builder subFactoriesBuilder) throws IOException {
102101
return new ChildrenAggregatorFactory(name, config, childFilter, parentFilter, queryShardContext, parent,
103102
subFactoriesBuilder, metaData);
104103
}
105104

106105
@Override
107-
protected ValuesSourceConfig<WithOrdinals> resolveConfig(QueryShardContext queryShardContext) {
108-
ValuesSourceConfig<WithOrdinals> config = new ValuesSourceConfig<>(CoreValuesSourceType.BYTES);
106+
protected ValuesSourceConfig resolveConfig(QueryShardContext queryShardContext) {
107+
ValuesSourceConfig config = new ValuesSourceConfig(CoreValuesSourceType.BYTES);
109108
joinFieldResolveConfig(queryShardContext, config);
110109
return config;
111110
}
112111

113-
private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig<WithOrdinals> config) {
112+
private void joinFieldResolveConfig(QueryShardContext queryShardContext, ValuesSourceConfig config) {
114113
ParentJoinFieldMapper parentJoinFieldMapper = ParentJoinFieldMapper.getMapper(queryShardContext.getMapperService());
115114
ParentIdFieldMapper parentIdFieldMapper = parentJoinFieldMapper.getParentIdFieldMapper(childType, false);
116115
if (parentIdFieldMapper != null) {

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import org.apache.lucene.search.Query;
2323
import org.elasticsearch.index.query.QueryShardContext;
24+
import org.elasticsearch.search.aggregations.AggregationExecutionException;
2425
import org.elasticsearch.search.aggregations.Aggregator;
2526
import org.elasticsearch.search.aggregations.AggregatorFactories;
2627
import org.elasticsearch.search.aggregations.AggregatorFactory;
2728
import org.elasticsearch.search.aggregations.InternalAggregation;
2829
import org.elasticsearch.search.aggregations.NonCollectingAggregator;
2930
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
31+
import org.elasticsearch.search.aggregations.support.ValuesSource;
3032
import org.elasticsearch.search.aggregations.support.ValuesSource.Bytes.WithOrdinals;
3133
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
3234
import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
@@ -36,13 +38,13 @@
3638
import java.util.List;
3739
import java.util.Map;
3840

39-
public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory<WithOrdinals> {
41+
public class ChildrenAggregatorFactory extends ValuesSourceAggregatorFactory {
4042

4143
private final Query parentFilter;
4244
private final Query childFilter;
4345

4446
public ChildrenAggregatorFactory(String name,
45-
ValuesSourceConfig<WithOrdinals> config,
47+
ValuesSourceConfig config,
4648
Query childFilter,
4749
Query parentFilter,
4850
QueryShardContext context,
@@ -67,12 +69,17 @@ public InternalAggregation buildEmptyAggregation() {
6769
}
6870

6971
@Override
70-
protected Aggregator doCreateInternal(WithOrdinals valuesSource,
72+
protected Aggregator doCreateInternal(ValuesSource rawValuesSource,
7173
SearchContext searchContext, Aggregator parent,
7274
boolean collectsFromSingleBucket,
7375
List<PipelineAggregator> pipelineAggregators,
7476
Map<String, Object> metaData) throws IOException {
7577

78+
if (rawValuesSource instanceof WithOrdinals == false) {
79+
throw new AggregationExecutionException("ValuesSource type " + rawValuesSource.toString() +
80+
"is not supported for aggregation " + this.name());
81+
}
82+
WithOrdinals valuesSource = (WithOrdinals) rawValuesSource;
7683
long maxOrd = valuesSource.globalMaxOrd(searchContext.searcher());
7784
if (collectsFromSingleBucket) {
7885
return new ParentToChildrenAggregator(name, factories, searchContext, parent, childFilter,

0 commit comments

Comments
 (0)