Skip to content

Commit ae0755d

Browse files
original-brownbearkcm
authored andcommitted
MINOR: Remove Deadcode in aggregtions.support (#34323)
* Removed methods are just unused (the exceptions being isGeoPoint() and is isFloatingPoint() but those could more efficiently be replaced by enum comparisons to simplify the code) * Remove exceptions aren't thrown
1 parent 056dac3 commit ae0755d

File tree

7 files changed

+17
-125
lines changed

7 files changed

+17
-125
lines changed

server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSource.java

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public abstract class MultiValuesSource <VS extends ValuesSource> {
3535

3636
public static class NumericMultiValuesSource extends MultiValuesSource<ValuesSource.Numeric> {
3737
public NumericMultiValuesSource(Map<String, ValuesSourceConfig<ValuesSource.Numeric>> valuesSourceConfigs,
38-
QueryShardContext context) throws IOException {
38+
QueryShardContext context) {
3939
values = new HashMap<>(valuesSourceConfigs.size());
4040
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.Numeric>> entry : valuesSourceConfigs.entrySet()) {
4141
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
@@ -51,42 +51,10 @@ public SortedNumericDoubleValues getField(String fieldName, LeafReaderContext ct
5151
}
5252
}
5353

54-
public static class BytesMultiValuesSource extends MultiValuesSource<ValuesSource.Bytes> {
55-
public BytesMultiValuesSource(Map<String, ValuesSourceConfig<ValuesSource.Bytes>> valuesSourceConfigs,
56-
QueryShardContext context) throws IOException {
57-
values = new HashMap<>(valuesSourceConfigs.size());
58-
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.Bytes>> entry : valuesSourceConfigs.entrySet()) {
59-
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
60-
}
61-
}
62-
63-
public Object getField(String fieldName, LeafReaderContext ctx) throws IOException {
64-
ValuesSource.Bytes value = values.get(fieldName);
65-
if (value == null) {
66-
throw new IllegalArgumentException("Could not find field name [" + fieldName + "] in multiValuesSource");
67-
}
68-
return value.bytesValues(ctx);
69-
}
70-
}
71-
72-
public static class GeoPointValuesSource extends MultiValuesSource<ValuesSource.GeoPoint> {
73-
public GeoPointValuesSource(Map<String, ValuesSourceConfig<ValuesSource.GeoPoint>> valuesSourceConfigs,
74-
QueryShardContext context) throws IOException {
75-
values = new HashMap<>(valuesSourceConfigs.size());
76-
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.GeoPoint>> entry : valuesSourceConfigs.entrySet()) {
77-
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
78-
}
79-
}
80-
}
81-
8254
public boolean needsScores() {
8355
return values.values().stream().anyMatch(ValuesSource::needsScores);
8456
}
8557

86-
public String[] fieldNames() {
87-
return values.keySet().toArray(new String[0]);
88-
}
89-
9058
public boolean areValuesSourcesEmpty() {
9159
return values.values().stream().allMatch(Objects::isNull);
9260
}

server/src/main/java/org/elasticsearch/search/aggregations/support/MultiValuesSourceAggregationBuilder.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ protected AB field(String propertyName, MultiValuesSourceFieldConfig config) {
139139
return (AB) this;
140140
}
141141

142-
public Map<String, MultiValuesSourceFieldConfig> fields() {
143-
return fields;
144-
}
145-
146142
/**
147143
* Sets the {@link ValueType} for the value produced by this aggregation
148144
*/
@@ -155,13 +151,6 @@ public AB valueType(ValueType valueType) {
155151
return (AB) this;
156152
}
157153

158-
/**
159-
* Gets the {@link ValueType} for the value produced by this aggregation
160-
*/
161-
public ValueType valueType() {
162-
return valueType;
163-
}
164-
165154
/**
166155
* Sets the format to use for the output of the aggregation.
167156
*/
@@ -174,13 +163,6 @@ public AB format(String format) {
174163
return (AB) this;
175164
}
176165

177-
/**
178-
* Gets the format to use for the output of the aggregation.
179-
*/
180-
public String format() {
181-
return format;
182-
}
183-
184166
@Override
185167
protected final MultiValuesSourceAggregatorFactory<VS, ?> doBuild(SearchContext context, AggregatorFactory<?> parent,
186168
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {

server/src/main/java/org/elasticsearch/search/aggregations/support/ValueType.java

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -38,52 +38,16 @@ public enum ValueType implements Writeable {
3838
IndexFieldData.class, DocValueFormat.RAW),
3939
LONG((byte) 2, "byte|short|integer|long", "long",
4040
ValuesSourceType.NUMERIC,
41-
IndexNumericFieldData.class, DocValueFormat.RAW) {
42-
@Override
43-
public boolean isNumeric() {
44-
return true;
45-
}
46-
},
47-
DOUBLE((byte) 3, "float|double", "double", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
48-
@Override
49-
public boolean isNumeric() {
50-
return true;
51-
}
52-
53-
@Override
54-
public boolean isFloatingPoint() {
55-
return true;
56-
}
57-
},
58-
NUMBER((byte) 4, "number", "number", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
59-
@Override
60-
public boolean isNumeric() {
61-
return true;
62-
}
63-
},
41+
IndexNumericFieldData.class, DocValueFormat.RAW),
42+
DOUBLE((byte) 3, "float|double", "double", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
43+
NUMBER((byte) 4, "number", "number", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
6444
DATE((byte) 5, "date", "date", ValuesSourceType.NUMERIC, IndexNumericFieldData.class,
65-
new DocValueFormat.DateTime(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER, DateTimeZone.UTC)) {
66-
@Override
67-
public boolean isNumeric() {
68-
return true;
69-
}
70-
},
45+
new DocValueFormat.DateTime(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER, DateTimeZone.UTC)),
7146
IP((byte) 6, "ip", "ip", ValuesSourceType.BYTES, IndexFieldData.class, DocValueFormat.IP),
7247
// TODO: what is the difference between "number" and "numeric"?
73-
NUMERIC((byte) 7, "numeric", "numeric", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
74-
@Override
75-
public boolean isNumeric() {
76-
return true;
77-
}
78-
},
79-
GEOPOINT((byte) 8, "geo_point", "geo_point", ValuesSourceType.GEOPOINT, IndexGeoPointFieldData.class, DocValueFormat.GEOHASH) {
80-
},
81-
BOOLEAN((byte) 9, "boolean", "boolean", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.BOOLEAN) {
82-
@Override
83-
public boolean isNumeric() {
84-
return super.isNumeric();
85-
}
86-
};
48+
NUMERIC((byte) 7, "numeric", "numeric", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
49+
GEOPOINT((byte) 8, "geo_point", "geo_point", ValuesSourceType.GEOPOINT, IndexGeoPointFieldData.class, DocValueFormat.GEOHASH),
50+
BOOLEAN((byte) 9, "boolean", "boolean", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.BOOLEAN);
8751

8852
final String description;
8953
final ValuesSourceType valuesSourceType;
@@ -125,14 +89,6 @@ public DocValueFormat defaultFormat() {
12589
return defaultFormat;
12690
}
12791

128-
public boolean isNumeric() {
129-
return false;
130-
}
131-
132-
public boolean isFloatingPoint() {
133-
return false;
134-
}
135-
13692
public static ValueType resolveForScript(String type) {
13793
switch (type) {
13894
case "string": return STRING;

server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public Script(AggregationScript.LeafFactory script, ValueType scriptValueType) {
385385

386386
@Override
387387
public boolean isFloatingPoint() {
388-
return scriptValueType != null ? scriptValueType.isFloatingPoint() : true;
388+
return scriptValueType != null ? scriptValueType == ValueType.DOUBLE : true;
389389
}
390390

391391
@Override

server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorFactory.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.elasticsearch.search.aggregations.AggregatorFactory;
2525
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
2626
import org.elasticsearch.search.internal.SearchContext;
27-
import org.joda.time.DateTimeZone;
2827

2928
import java.io.IOException;
3029
import java.util.List;
@@ -41,14 +40,6 @@ public ValuesSourceAggregatorFactory(String name, ValuesSourceConfig<VS> config,
4140
this.config = config;
4241
}
4342

44-
public DateTimeZone timeZone() {
45-
return config.timezone();
46-
}
47-
48-
public ValuesSourceConfig<VS> getConfig() {
49-
return config;
50-
}
51-
5243
@Override
5344
public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket,
5445
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {

server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceConfig.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.elasticsearch.search.aggregations.AggregationExecutionException;
3434
import org.joda.time.DateTimeZone;
3535

36-
import java.io.IOException;
37-
3836
/**
3937
* A configuration that tells aggregations how to retrieve data from the index
4038
* in order to run a specific aggregation.
@@ -66,7 +64,7 @@ public static <VS extends ValuesSource> ValuesSourceConfig<VS> resolve(
6664
// on Bytes
6765
valuesSourceType = ValuesSourceType.BYTES;
6866
}
69-
ValuesSourceConfig<VS> config = new ValuesSourceConfig<VS>(valuesSourceType);
67+
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
7068
config.missing(missing);
7169
config.timezone(timeZone);
7270
config.format(resolveFormat(format, valueType));
@@ -220,7 +218,7 @@ public DocValueFormat format() {
220218
/** Get a value source given its configuration. A return value of null indicates that
221219
* no value source could be built. */
222220
@Nullable
223-
public VS toValuesSource(QueryShardContext context) throws IOException {
221+
public VS toValuesSource(QueryShardContext context) {
224222
if (!valid()) {
225223
throw new IllegalStateException(
226224
"value source config is invalid; must have either a field context or a script or marked as unwrapped");
@@ -271,7 +269,7 @@ public VS toValuesSource(QueryShardContext context) throws IOException {
271269
/**
272270
* Return the original values source, before we apply `missing`.
273271
*/
274-
private VS originalValuesSource() throws IOException {
272+
private VS originalValuesSource() {
275273
if (fieldContext() == null) {
276274
if (valueSourceType() == ValuesSourceType.NUMERIC) {
277275
return (VS) numericScript();
@@ -293,11 +291,11 @@ private VS originalValuesSource() throws IOException {
293291
return (VS) bytesField();
294292
}
295293

296-
private ValuesSource.Numeric numericScript() throws IOException {
294+
private ValuesSource.Numeric numericScript() {
297295
return new ValuesSource.Numeric.Script(script(), scriptValueType());
298296
}
299297

300-
private ValuesSource.Numeric numericField() throws IOException {
298+
private ValuesSource.Numeric numericField() {
301299

302300
if (!(fieldContext().indexFieldData() instanceof IndexNumericFieldData)) {
303301
throw new IllegalArgumentException("Expected numeric type on field [" + fieldContext().field() +
@@ -311,7 +309,7 @@ private ValuesSource.Numeric numericField() throws IOException {
311309
return dataSource;
312310
}
313311

314-
private ValuesSource bytesField() throws IOException {
312+
private ValuesSource bytesField() {
315313
final IndexFieldData<?> indexFieldData = fieldContext().indexFieldData();
316314
ValuesSource dataSource;
317315
if (indexFieldData instanceof IndexOrdinalsFieldData) {
@@ -325,11 +323,11 @@ private ValuesSource bytesField() throws IOException {
325323
return dataSource;
326324
}
327325

328-
private ValuesSource.Bytes bytesScript() throws IOException {
326+
private ValuesSource.Bytes bytesScript() {
329327
return new ValuesSource.Bytes.Script(script());
330328
}
331329

332-
private ValuesSource.GeoPoint geoPointField() throws IOException {
330+
private ValuesSource.GeoPoint geoPointField() {
333331

334332
if (!(fieldContext().indexFieldData() instanceof IndexGeoPointFieldData)) {
335333
throw new IllegalArgumentException("Expected geo_point type on field [" + fieldContext().field() +

server/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceType.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.elasticsearch.search.aggregations.support;
2121

22-
import org.elasticsearch.common.ParseField;
2322
import org.elasticsearch.common.io.stream.StreamInput;
2423
import org.elasticsearch.common.io.stream.StreamOutput;
2524
import org.elasticsearch.common.io.stream.Writeable;
@@ -33,8 +32,6 @@ public enum ValuesSourceType implements Writeable {
3332
BYTES,
3433
GEOPOINT;
3534

36-
public static final ParseField VALUE_SOURCE_TYPE = new ParseField("value_source_type");
37-
3835
public static ValuesSourceType fromString(String name) {
3936
return valueOf(name.trim().toUpperCase(Locale.ROOT));
4037
}

0 commit comments

Comments
 (0)