Skip to content

Commit

Permalink
Misc dead code cleanup o.e.e.search (elastic#102617)
Browse files Browse the repository at this point in the history
Misc obvious cleanup of unused methods and unused parameters.
  • Loading branch information
original-brownbear authored and timgrein committed Nov 30, 2023
1 parent 682fca9 commit 0977883
Show file tree
Hide file tree
Showing 19 changed files with 20 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ void sortBuffer() {
}
}

synchronized long addWithoutBreaking(long size) {
synchronized void addWithoutBreaking(long size) {
circuitBreaker.addWithoutBreaking(size);
circuitBreakerBytes += size;
maxAggsCurrentBufferSize = Math.max(maxAggsCurrentBufferSize, circuitBreakerBytes);
return circuitBreakerBytes;
}

synchronized long addEstimateAndMaybeBreak(long estimatedSize) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,6 @@ public void setCcsMinimizeRoundtrips(boolean ccsMinimizeRoundtrips) {
this.ccsMinimizeRoundtrips = ccsMinimizeRoundtrips;
}

/**
* Returns the default value of {@link #ccsMinimizeRoundtrips} of a search request
*/
public static boolean defaultCcsMinimizeRoundtrips(SearchRequest request) {
return request.minCompatibleShardNode == null;
}

/**
* A comma separated list of routing values to control the shards the search will be executed on.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private NumericDoubleValues getNumericDocValues(LeafReaderContext context, doubl
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE;
return sortMode.select(values, missingValue, rootDocs, innerDocs, context.reader().maxDoc(), maxChildren);
return sortMode.select(values, missingValue, rootDocs, innerDocs, maxChildren);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private NumericDoubleValues getNumericDocValues(LeafReaderContext context, float
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE;
return sortMode.select(values, missingValue, rootDocs, innerDocs, context.reader().maxDoc(), maxChildren);
return sortMode.select(values, missingValue, rootDocs, innerDocs, maxChildren);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ public NumericDoubleValues select(
final double missingValue,
final BitSet parentDocs,
final DocIdSetIterator childDocs,
int maxDoc,
int maxChildren
) throws IOException {
if (parentDocs == null || childDocs == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,7 @@ private static String key(String key, Double from, Double to) {
if (key != null) {
return key;
}
StringBuilder sb = new StringBuilder();
sb.append((from == null || from == 0) ? "*" : from);
sb.append("-");
sb.append((to == null || Double.isInfinite(to)) ? "*" : to);
return sb.toString();
return ((from == null || from == 0) ? "*" : from) + "-" + ((to == null || Double.isInfinite(to)) ? "*" : to);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ public Bucket(
}

private static String generateKey(BytesRef from, BytesRef to, DocValueFormat format) {
StringBuilder builder = new StringBuilder().append(from == null ? "*" : format.format(from))
.append("-")
.append(to == null ? "*" : format.format(to));
return builder.toString();
return (from == null ? "*" : format.format(from)) + "-" + (to == null ? "*" : format.format(to));
}

private static Bucket createFromStream(StreamInput in, DocValueFormat format, boolean keyed) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
}

private static String generateKey(double from, double to, DocValueFormat format) {
StringBuilder builder = new StringBuilder().append(Double.isInfinite(from) ? "*" : format.format(from))
.append("-")
.append(Double.isInfinite(to) ? "*" : format.format(to));
return builder.toString();
return (Double.isInfinite(from) ? "*" : format.format(from)) + "-" + (Double.isInfinite(to) ? "*" : format.format(to));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected static void declareParsedRangeFields(
final CheckedFunction<XContentParser, ParsedBucket, IOException> bucketParser,
final CheckedFunction<XContentParser, ParsedBucket, IOException> keyedBucketParser
) {
declareMultiBucketAggregationFields(objectParser, bucketParser::apply, keyedBucketParser::apply);
declareMultiBucketAggregationFields(objectParser, bucketParser, keyedBucketParser);
}

private static final ObjectParser<ParsedRange, Void> PARSER = new ObjectParser<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public abstract class InternalMappedRareTerms<A extends InternalRareTerms<A, B>,

protected DocValueFormat format;
protected List<B> buckets;
protected Map<String, B> bucketMap;

final SetBackedScalingCuckooFilter filter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,11 @@ public boolean hasMetric(String name) {
public double metric(String name, long owningBucketOrd) {
if (owningBucketOrd >= counts.size()) {
return switch (InternalExtendedStats.Metrics.resolve(name)) {
case count -> 0;
case sum -> 0;
case count, sum_of_squares, sum -> 0;
case min -> Double.POSITIVE_INFINITY;
case max -> Double.NEGATIVE_INFINITY;
case avg -> Double.NaN;
case sum_of_squares -> 0;
case variance -> Double.NaN;
case variance_population -> Double.NaN;
case variance_sampling -> Double.NaN;
case std_deviation -> Double.NaN;
case std_deviation_population -> Double.NaN;
case std_deviation_sampling -> Double.NaN;
case std_upper -> Double.NaN;
case std_lower -> Double.NaN;
case avg, variance, variance_population, variance_sampling, std_deviation, std_deviation_population, std_deviation_sampling,
std_upper, std_lower -> Double.NaN;
default -> throw new IllegalArgumentException("Unknown value [" + name + "] in common stats aggregation");
};
}
Expand All @@ -167,9 +158,7 @@ public double metric(String name, long owningBucketOrd) {
case variance -> variance(owningBucketOrd);
case variance_population -> variancePopulation(owningBucketOrd);
case variance_sampling -> varianceSampling(owningBucketOrd);
case std_deviation -> Math.sqrt(variance(owningBucketOrd));
case std_deviation_population -> Math.sqrt(variance(owningBucketOrd));
case std_deviation_sampling -> Math.sqrt(varianceSampling(owningBucketOrd));
case std_deviation, std_deviation_population, std_deviation_sampling -> Math.sqrt(variance(owningBucketOrd));
case std_upper -> (sums.get(owningBucketOrd) / counts.get(owningBucketOrd)) + (Math.sqrt(variance(owningBucketOrd))
* this.sigma);
case std_lower -> (sums.get(owningBucketOrd) / counts.get(owningBucketOrd)) - (Math.sqrt(variance(owningBucketOrd))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public boolean hasMetric(String name) {
public double metric(String name, long owningBucketOrd) {
if (owningBucketOrd >= counts.size()) {
return switch (InternalStats.Metrics.resolve(name)) {
case count -> 0;
case sum -> 0;
case count, sum -> 0;
case min -> Double.POSITIVE_INFINITY;
case max -> Double.NEGATIVE_INFINITY;
case avg -> Double.NaN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ private static ValuesSourceConfig internalResolve(
aggregationScript,
scriptValueType,
missing,
timeZone,
docValueFormat,
context::nowInMillis
);
Expand Down Expand Up @@ -258,14 +257,14 @@ private static DocValueFormat resolveFormat(
public static ValuesSourceConfig resolveFieldOnly(MappedFieldType fieldType, AggregationContext context) {
FieldContext fieldContext = context.buildFieldContext(fieldType);
ValuesSourceType vstype = fieldContext.indexFieldData().getValuesSourceType();
return new ValuesSourceConfig(vstype, fieldContext, false, null, null, null, null, null, context::nowInMillis);
return new ValuesSourceConfig(vstype, fieldContext, false, null, null, null, null, context::nowInMillis);
}

/**
* Convenience method for creating unmapped configs
*/
public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceType, AggregationContext context) {
return new ValuesSourceConfig(valuesSourceType, null, true, null, null, null, null, null, context::nowInMillis);
return new ValuesSourceConfig(valuesSourceType, null, true, null, null, null, null, context::nowInMillis);
}

private final ValuesSourceType valuesSourceType;
Expand All @@ -275,7 +274,6 @@ public static ValuesSourceConfig resolveUnmapped(ValuesSourceType valuesSourceTy
private final boolean unmapped;
private final DocValueFormat format;
private final Object missing;
private final ZoneId timeZone;
private final ValuesSource valuesSource;

@SuppressWarnings("this-escape")
Expand All @@ -286,7 +284,6 @@ public ValuesSourceConfig(
AggregationScript.LeafFactory script,
ValueType scriptValueType,
Object missing,
ZoneId timeZone,
DocValueFormat format,
LongSupplier nowInMillis
) {
Expand All @@ -299,7 +296,6 @@ public ValuesSourceConfig(
this.script = script;
this.scriptValueType = scriptValueType;
this.missing = missing;
this.timeZone = timeZone;
this.format = format == null ? DocValueFormat.RAW : format;

if (valid() == false) {
Expand Down Expand Up @@ -383,10 +379,6 @@ public Object missing() {
return this.missing;
}

public ZoneId timezone() {
return this.timeZone;
}

public DocValueFormat format() {
return format;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ public int hashCode() {
}
}

@SuppressWarnings("rawtypes")
public static final RegistryKey UNREGISTERED_KEY = new RegistryKey<>("unregistered", RegistryKey.class);

public static class Builder {
private final AggregationUsageService.Builder usageServiceBuilder;
private final Map<RegistryKey<?>, List<Map.Entry<ValuesSourceType, ?>>> aggregatorRegistry = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,18 @@ static Object convertValueFromSortField(Object value, SortField sortField, DocVa
private static Object convertValueFromSortType(String fieldName, SortField.Type sortType, Object value, DocValueFormat format) {
try {
switch (sortType) {
case DOC:
case DOC, INT:
if (value instanceof Number) {
return ((Number) value).intValue();
}
return Integer.parseInt(value.toString());

case SCORE:
case SCORE, FLOAT:
if (value instanceof Number) {
return ((Number) value).floatValue();
}
return Float.parseFloat(value.toString());

case INT:
if (value instanceof Number) {
return ((Number) value).intValue();
}
return Integer.parseInt(value.toString());

case DOUBLE:
if (value instanceof Number) {
return ((Number) value).doubleValue();
Expand All @@ -187,12 +181,6 @@ private static Object convertValueFromSortType(String fieldName, SortField.Type
() -> { throw new IllegalStateException("now() is not allowed in [search_after] key"); }
);

case FLOAT:
if (value instanceof Number) {
return ((Number) value).floatValue();
}
return Float.parseFloat(value.toString());

case STRING_VAL:
case STRING:
if (value instanceof BytesRef bytesRef) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,7 @@ private NumericDoubleValues getNumericDoubleValues(LeafReaderContext context) th
final BitSet rootDocs = nested.rootDocs(context);
final DocIdSetIterator innerDocs = nested.innerDocs(context);
final int maxChildren = nested.getNestedSort() != null ? nested.getNestedSort().getMaxChildren() : Integer.MAX_VALUE;
return localSortMode.select(
distanceValues,
Double.POSITIVE_INFINITY,
rootDocs,
innerDocs,
context.reader().maxDoc(),
maxChildren
);
return localSortMode.select(distanceValues, Double.POSITIVE_INFINITY, rootDocs, innerDocs, maxChildren);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ private void verifySortedNumericDouble(
missingValue,
rootDocs,
new BitSetIterator(innerDocs, 0L),
maxDoc,
maxChildren
);
int prevRoot = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ protected ValuesSourceConfig resolveConfig(AggregationContext context) {
null,
null,
1.0,
null,
DocValueFormat.RAW,
context::nowInMillis
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private <T> void checkLicenseNotRequired(
ValuesSourceRegistry registry = registryBuilder.build();
T aggregator = registry.getAggregator(
registryKey,
new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null, null)
new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null)
);
NullPointerException exception = expectThrows(NullPointerException.class, () -> builder.accept(aggregator));
assertThat(
Expand Down Expand Up @@ -203,7 +203,7 @@ private <T> void checkLicenseRequired(
ValuesSourceRegistry registry = registryBuilder.build();
T aggregator = registry.getAggregator(
registryKey,
new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null, null)
new ValuesSourceConfig(sourceType, null, true, null, null, null, null, null)
);
if (License.OperationMode.TRIAL != operationMode
&& License.OperationMode.compare(operationMode, License.OperationMode.GOLD) < 0) {
Expand All @@ -229,7 +229,7 @@ private <T> void checkLicenseRequired(

private static class TestValuesSourceConfig extends ValuesSourceConfig {
private TestValuesSourceConfig(ValuesSourceType sourceType) {
super(sourceType, null, true, null, null, null, null, null, null);
super(sourceType, null, true, null, null, null, null, null);
}
}
}

0 comments on commit 0977883

Please sign in to comment.