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
This commit is contained in:
parent
55d48e4cc1
commit
64a044240a
|
@ -35,7 +35,7 @@ public abstract class MultiValuesSource <VS extends ValuesSource> {
|
|||
|
||||
public static class NumericMultiValuesSource extends MultiValuesSource<ValuesSource.Numeric> {
|
||||
public NumericMultiValuesSource(Map<String, ValuesSourceConfig<ValuesSource.Numeric>> valuesSourceConfigs,
|
||||
QueryShardContext context) throws IOException {
|
||||
QueryShardContext context) {
|
||||
values = new HashMap<>(valuesSourceConfigs.size());
|
||||
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.Numeric>> entry : valuesSourceConfigs.entrySet()) {
|
||||
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
|
||||
|
@ -51,42 +51,10 @@ public abstract class MultiValuesSource <VS extends ValuesSource> {
|
|||
}
|
||||
}
|
||||
|
||||
public static class BytesMultiValuesSource extends MultiValuesSource<ValuesSource.Bytes> {
|
||||
public BytesMultiValuesSource(Map<String, ValuesSourceConfig<ValuesSource.Bytes>> valuesSourceConfigs,
|
||||
QueryShardContext context) throws IOException {
|
||||
values = new HashMap<>(valuesSourceConfigs.size());
|
||||
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.Bytes>> entry : valuesSourceConfigs.entrySet()) {
|
||||
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
|
||||
}
|
||||
}
|
||||
|
||||
public Object getField(String fieldName, LeafReaderContext ctx) throws IOException {
|
||||
ValuesSource.Bytes value = values.get(fieldName);
|
||||
if (value == null) {
|
||||
throw new IllegalArgumentException("Could not find field name [" + fieldName + "] in multiValuesSource");
|
||||
}
|
||||
return value.bytesValues(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GeoPointValuesSource extends MultiValuesSource<ValuesSource.GeoPoint> {
|
||||
public GeoPointValuesSource(Map<String, ValuesSourceConfig<ValuesSource.GeoPoint>> valuesSourceConfigs,
|
||||
QueryShardContext context) throws IOException {
|
||||
values = new HashMap<>(valuesSourceConfigs.size());
|
||||
for (Map.Entry<String, ValuesSourceConfig<ValuesSource.GeoPoint>> entry : valuesSourceConfigs.entrySet()) {
|
||||
values.put(entry.getKey(), entry.getValue().toValuesSource(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean needsScores() {
|
||||
return values.values().stream().anyMatch(ValuesSource::needsScores);
|
||||
}
|
||||
|
||||
public String[] fieldNames() {
|
||||
return values.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
public boolean areValuesSourcesEmpty() {
|
||||
return values.values().stream().allMatch(Objects::isNull);
|
||||
}
|
||||
|
|
|
@ -139,10 +139,6 @@ public abstract class MultiValuesSourceAggregationBuilder<VS extends ValuesSourc
|
|||
return (AB) this;
|
||||
}
|
||||
|
||||
public Map<String, MultiValuesSourceFieldConfig> fields() {
|
||||
return fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ValueType} for the value produced by this aggregation
|
||||
*/
|
||||
|
@ -155,13 +151,6 @@ public abstract class MultiValuesSourceAggregationBuilder<VS extends ValuesSourc
|
|||
return (AB) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ValueType} for the value produced by this aggregation
|
||||
*/
|
||||
public ValueType valueType() {
|
||||
return valueType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the format to use for the output of the aggregation.
|
||||
*/
|
||||
|
@ -174,13 +163,6 @@ public abstract class MultiValuesSourceAggregationBuilder<VS extends ValuesSourc
|
|||
return (AB) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the format to use for the output of the aggregation.
|
||||
*/
|
||||
public String format() {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final MultiValuesSourceAggregatorFactory<VS, ?> doBuild(SearchContext context, AggregatorFactory<?> parent,
|
||||
AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
|
||||
|
|
|
@ -38,52 +38,16 @@ public enum ValueType implements Writeable {
|
|||
IndexFieldData.class, DocValueFormat.RAW),
|
||||
LONG((byte) 2, "byte|short|integer|long", "long",
|
||||
ValuesSourceType.NUMERIC,
|
||||
IndexNumericFieldData.class, DocValueFormat.RAW) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
DOUBLE((byte) 3, "float|double", "double", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloatingPoint() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
NUMBER((byte) 4, "number", "number", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
IndexNumericFieldData.class, DocValueFormat.RAW),
|
||||
DOUBLE((byte) 3, "float|double", "double", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
|
||||
NUMBER((byte) 4, "number", "number", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
|
||||
DATE((byte) 5, "date", "date", ValuesSourceType.NUMERIC, IndexNumericFieldData.class,
|
||||
new DocValueFormat.DateTime(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER, DateTimeZone.UTC)) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
new DocValueFormat.DateTime(DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER, DateTimeZone.UTC)),
|
||||
IP((byte) 6, "ip", "ip", ValuesSourceType.BYTES, IndexFieldData.class, DocValueFormat.IP),
|
||||
// TODO: what is the difference between "number" and "numeric"?
|
||||
NUMERIC((byte) 7, "numeric", "numeric", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
GEOPOINT((byte) 8, "geo_point", "geo_point", ValuesSourceType.GEOPOINT, IndexGeoPointFieldData.class, DocValueFormat.GEOHASH) {
|
||||
},
|
||||
BOOLEAN((byte) 9, "boolean", "boolean", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.BOOLEAN) {
|
||||
@Override
|
||||
public boolean isNumeric() {
|
||||
return super.isNumeric();
|
||||
}
|
||||
};
|
||||
NUMERIC((byte) 7, "numeric", "numeric", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.RAW),
|
||||
GEOPOINT((byte) 8, "geo_point", "geo_point", ValuesSourceType.GEOPOINT, IndexGeoPointFieldData.class, DocValueFormat.GEOHASH),
|
||||
BOOLEAN((byte) 9, "boolean", "boolean", ValuesSourceType.NUMERIC, IndexNumericFieldData.class, DocValueFormat.BOOLEAN);
|
||||
|
||||
final String description;
|
||||
final ValuesSourceType valuesSourceType;
|
||||
|
@ -125,14 +89,6 @@ public enum ValueType implements Writeable {
|
|||
return defaultFormat;
|
||||
}
|
||||
|
||||
public boolean isNumeric() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isFloatingPoint() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static ValueType resolveForScript(String type) {
|
||||
switch (type) {
|
||||
case "string": return STRING;
|
||||
|
|
|
@ -385,7 +385,7 @@ public abstract class ValuesSource {
|
|||
|
||||
@Override
|
||||
public boolean isFloatingPoint() {
|
||||
return scriptValueType != null ? scriptValueType.isFloatingPoint() : true;
|
||||
return scriptValueType != null ? scriptValueType == ValueType.DOUBLE : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.elasticsearch.search.aggregations.AggregatorFactories;
|
|||
import org.elasticsearch.search.aggregations.AggregatorFactory;
|
||||
import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
|
||||
import org.elasticsearch.search.internal.SearchContext;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
@ -41,14 +40,6 @@ public abstract class ValuesSourceAggregatorFactory<VS extends ValuesSource, AF
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
public DateTimeZone timeZone() {
|
||||
return config.timezone();
|
||||
}
|
||||
|
||||
public ValuesSourceConfig<VS> getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Aggregator createInternal(Aggregator parent, boolean collectsFromSingleBucket,
|
||||
List<PipelineAggregator> pipelineAggregators, Map<String, Object> metaData) throws IOException {
|
||||
|
|
|
@ -33,8 +33,6 @@ import org.elasticsearch.search.DocValueFormat;
|
|||
import org.elasticsearch.search.aggregations.AggregationExecutionException;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* A configuration that tells aggregations how to retrieve data from the index
|
||||
* in order to run a specific aggregation.
|
||||
|
@ -66,7 +64,7 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
// on Bytes
|
||||
valuesSourceType = ValuesSourceType.BYTES;
|
||||
}
|
||||
ValuesSourceConfig<VS> config = new ValuesSourceConfig<VS>(valuesSourceType);
|
||||
ValuesSourceConfig<VS> config = new ValuesSourceConfig<>(valuesSourceType);
|
||||
config.missing(missing);
|
||||
config.timezone(timeZone);
|
||||
config.format(resolveFormat(format, valueType));
|
||||
|
@ -220,7 +218,7 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
/** Get a value source given its configuration. A return value of null indicates that
|
||||
* no value source could be built. */
|
||||
@Nullable
|
||||
public VS toValuesSource(QueryShardContext context) throws IOException {
|
||||
public VS toValuesSource(QueryShardContext context) {
|
||||
if (!valid()) {
|
||||
throw new IllegalStateException(
|
||||
"value source config is invalid; must have either a field context or a script or marked as unwrapped");
|
||||
|
@ -271,7 +269,7 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
/**
|
||||
* Return the original values source, before we apply `missing`.
|
||||
*/
|
||||
private VS originalValuesSource() throws IOException {
|
||||
private VS originalValuesSource() {
|
||||
if (fieldContext() == null) {
|
||||
if (valueSourceType() == ValuesSourceType.NUMERIC) {
|
||||
return (VS) numericScript();
|
||||
|
@ -293,11 +291,11 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
return (VS) bytesField();
|
||||
}
|
||||
|
||||
private ValuesSource.Numeric numericScript() throws IOException {
|
||||
private ValuesSource.Numeric numericScript() {
|
||||
return new ValuesSource.Numeric.Script(script(), scriptValueType());
|
||||
}
|
||||
|
||||
private ValuesSource.Numeric numericField() throws IOException {
|
||||
private ValuesSource.Numeric numericField() {
|
||||
|
||||
if (!(fieldContext().indexFieldData() instanceof IndexNumericFieldData)) {
|
||||
throw new IllegalArgumentException("Expected numeric type on field [" + fieldContext().field() +
|
||||
|
@ -311,7 +309,7 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
return dataSource;
|
||||
}
|
||||
|
||||
private ValuesSource bytesField() throws IOException {
|
||||
private ValuesSource bytesField() {
|
||||
final IndexFieldData<?> indexFieldData = fieldContext().indexFieldData();
|
||||
ValuesSource dataSource;
|
||||
if (indexFieldData instanceof IndexOrdinalsFieldData) {
|
||||
|
@ -325,11 +323,11 @@ public class ValuesSourceConfig<VS extends ValuesSource> {
|
|||
return dataSource;
|
||||
}
|
||||
|
||||
private ValuesSource.Bytes bytesScript() throws IOException {
|
||||
private ValuesSource.Bytes bytesScript() {
|
||||
return new ValuesSource.Bytes.Script(script());
|
||||
}
|
||||
|
||||
private ValuesSource.GeoPoint geoPointField() throws IOException {
|
||||
private ValuesSource.GeoPoint geoPointField() {
|
||||
|
||||
if (!(fieldContext().indexFieldData() instanceof IndexGeoPointFieldData)) {
|
||||
throw new IllegalArgumentException("Expected geo_point type on field [" + fieldContext().field() +
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
package org.elasticsearch.search.aggregations.support;
|
||||
|
||||
import org.elasticsearch.common.ParseField;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.io.stream.Writeable;
|
||||
|
@ -33,8 +32,6 @@ public enum ValuesSourceType implements Writeable {
|
|||
BYTES,
|
||||
GEOPOINT;
|
||||
|
||||
public static final ParseField VALUE_SOURCE_TYPE = new ParseField("value_source_type");
|
||||
|
||||
public static ValuesSourceType fromString(String name) {
|
||||
return valueOf(name.trim().toUpperCase(Locale.ROOT));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue