Skip to content

Commit

Permalink
Remvoe some more dead code from o.e.search.aggregations (elastic#121498
Browse files Browse the repository at this point in the history
…) (elastic#121813)

Just some obvious dead code removal.
  • Loading branch information
original-brownbear authored Feb 5, 2025
1 parent d6762f6 commit e825825
Show file tree
Hide file tree
Showing 32 changed files with 34 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ private List<B> reducePipelineBuckets(AggregationReduceContext reduceContext, Pi
List<B> reducedBuckets = new ArrayList<>();
for (B bucket : getBuckets()) {
List<InternalAggregation> aggs = new ArrayList<>();
for (Aggregation agg : bucket.getAggregations()) {
for (InternalAggregation agg : bucket.getAggregations()) {
PipelineTree subTree = pipelineTree.subTree(agg.getName());
aggs.add(((InternalAggregation) agg).reducePipelines((InternalAggregation) agg, reduceContext, subTree));
aggs.add(agg.reducePipelines(agg, reduceContext, subTree));
}
reducedBuckets.add(createBucket(InternalAggregations.from(aggs), bucket));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public InvalidAggregationPathException(String msg) {
super(msg);
}

public InvalidAggregationPathException(String msg, Throwable cause) {
super(msg, cause);
}

public InvalidAggregationPathException(StreamInput in) throws IOException {
super(in);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ protected LeafBucketCollector getLeafCollector(AggregationExecutionContext aggCt
// Visit documents sorted by the leading source of the composite definition and terminates
// when the leading source value is guaranteed to be greater than the lowest composite bucket
// in the queue.
DocIdSet docIdSet = sortedDocsProducer.processLeaf(topLevelQuery(), queue, aggCtx.getLeafReaderContext(), fillDocIdSet);
DocIdSet docIdSet = sortedDocsProducer.processLeaf(queue, aggCtx.getLeafReaderContext(), fillDocIdSet);
if (fillDocIdSet) {
entries.add(new Entry(aggCtx, docIdSet));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.apache.lucene.index.PointValues;
import org.apache.lucene.search.CollectionTerminatedException;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.DocIdSetBuilder;

import java.io.IOException;
Expand All @@ -36,8 +35,7 @@ class PointsSortedDocsProducer extends SortedDocsProducer {
}

@Override
DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet)
throws IOException {
DocIdSet processLeaf(CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet) throws IOException {
final PointValues values = context.reader().getPointValues(field);
if (values == null) {
// no value for the field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.DocIdSetIterator;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.DocIdSetBuilder;
import org.elasticsearch.core.Nullable;
Expand Down Expand Up @@ -99,6 +98,5 @@ public void collect(int doc, long bucket) throws IOException {
* Returns the {@link DocIdSet} of the documents that contain a top composite bucket in this leaf or
* {@link DocIdSet#EMPTY} if <code>fillDocIdSet</code> is false.
*/
abstract DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet)
throws IOException;
abstract DocIdSet processLeaf(CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.DocIdSetBuilder;

Expand All @@ -29,8 +28,7 @@ class TermsSortedDocsProducer extends SortedDocsProducer {
}

@Override
DocIdSet processLeaf(Query query, CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet)
throws IOException {
DocIdSet processLeaf(CompositeValuesCollectorQueue queue, LeafReaderContext context, boolean fillDocIdSet) throws IOException {
final Terms terms = context.reader().terms(field);
if (terms == null) {
// no value for the field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,7 @@ public class InternalDateRange extends InternalRange<InternalDateRange.Bucket, I

public static class Bucket extends InternalRange.Bucket {

public Bucket(
String key,
double from,
double to,
long docCount,
List<InternalAggregation> aggregations,
boolean keyed,
DocValueFormat formatter
) {
public Bucket(String key, double from, double to, long docCount, List<InternalAggregation> aggregations, DocValueFormat formatter) {
super(key, from, to, docCount, InternalAggregations.from(aggregations), formatter);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@ public interface BucketOrdsEnum {
* Read the current value.
*/
void readValue(BytesRef dest);

/**
* An {@linkplain BucketOrdsEnum} that is empty.
*/
BucketOrdsEnum EMPTY = new BucketOrdsEnum() {
@Override
public boolean next() {
return false;
}

@Override
public long ord() {
return 0;
}

@Override
public void readValue(BytesRef dest) {}
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ protected Bucket(long subsetDf, long supersetDf, InternalAggregations aggregatio
/**
* Read from a stream.
*/
protected Bucket(StreamInput in, DocValueFormat format) {
protected Bucket(DocValueFormat format) {
this.format = format;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public Bucket(long subsetDf, long supersetDf, long term, InternalAggregations ag
}

Bucket(StreamInput in, DocValueFormat format) throws IOException {
super(in, format);
super(format);
subsetDf = in.readVLong();
supersetDf = in.readVLong();
term = in.readLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public Bucket(
* Read from a stream.
*/
public Bucket(StreamInput in, DocValueFormat format) throws IOException {
super(in, format);
super(format);
termBytes = in.readBytesRef();
subsetDf = in.readVLong();
supersetDf = in.readVLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ protected DoubleHistogram getState(long bucketOrd) {
if (bucketOrd >= states.size()) {
return null;
}
final DoubleHistogram state = states.get(bucketOrd);
return state;
return states.get(bucketOrd);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public AbstractHyperLogLogPlusPlus(int precision) {
/** Get HyperLogLog algorithm */
protected abstract AbstractHyperLogLog.RunLenIterator getHyperLogLog(long bucketOrd);

/** Get the number of data structures */
public abstract long maxOrd();

/** Collect a value in the given bucket */
public abstract void collect(long bucketOrd, long hash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public AbstractLinearCounting(int precision) {
*/
protected abstract int size(long bucketOrd);

/**
* return the current values in the counter.
*/
protected abstract HashesIterator values(long bucketOrd);

public int collect(long bucketOrd, long hash) {
final int k = encodeHash(hash, p);
return addEncoded(bucketOrd, k);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ public interface ExtendedStats extends Stats {
*/
String getStdDeviationSamplingAsString();

/**
* The upper or lower bounds of stdDev of the collected values as a String.
*/
String getStdDeviationBoundAsString(Bounds bound);

/**
* The sum of the squares of the collected values as a String.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public HyperLogLogPlusPlus(int precision, BigArrays bigArrays, long initialBucke
this.algorithm = algorithm;
}

@Override
public long maxOrd() {
return hll.maxOrd();
}
Expand Down Expand Up @@ -322,8 +321,7 @@ protected int size(long bucketOrd) {
return size;
}

@Override
protected HashesIterator values(long bucketOrd) {
private HashesIterator values(long bucketOrd) {
// Make a fresh BytesRef for reading scratch work because this method can be called on many threads
return new LinearCountingIterator(this, new BytesRef(), bucketOrd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ final class HyperLogLogPlusPlusSparse extends AbstractHyperLogLogPlusPlus implem
this.lc = new LinearCounting(precision, bigArrays, initialBuckets);
}

@Override
public long maxOrd() {
return lc.sizes.size();
}

/** Needs to be called before adding elements into a bucket */
protected void ensureCapacity(long bucketOrd, long size) {
lc.ensureCapacity(bucketOrd, size);
Expand Down Expand Up @@ -135,8 +130,7 @@ protected int size(long bucketOrd) {
return size;
}

@Override
protected HashesIterator values(long bucketOrd) {
private HashesIterator values(long bucketOrd) {
return new LinearCountingIterator(values.get(bucketOrd), size(bucketOrd));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ public Object getProperty(List<String> path) {
};
} else if (path.size() == 2) {
BoundingBox<T> bbox = resolveBoundingBox();
T cornerPoint = null;
String cornerString = path.get(0);
cornerPoint = switch (cornerString) {
T cornerPoint = switch (cornerString) {
case "top_left" -> bbox.topLeft();
case "bottom_right" -> bbox.bottomRight();
default -> throw new IllegalArgumentException("Found unknown path element [" + cornerString + "] in [" + getName() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,7 @@ public String getStdDeviationSamplingAsString() {
return valueAsString(Metrics.std_deviation_sampling.name());
}

@Override
public String getStdDeviationBoundAsString(Bounds bound) {
private String getStdDeviationBoundAsString(Bounds bound) {
return switch (bound) {
case UPPER -> valueAsString(Metrics.std_upper.name());
case LOWER -> valueAsString(Metrics.std_lower.name());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,6 @@ protected MultiValue(StreamInput in) throws IOException {
super(in);
}

/**
* Read from a stream.
*
* @param readFormat whether to read the "format" field
*/
protected MultiValue(StreamInput in, boolean readFormat) throws IOException {
super(in, readFormat);
}

public abstract double value(String name);

public String valueAsString(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public static TopHitsAggregationBuilder parse(String aggregationName, XContentPa
factory.fetchSource(FetchSourceContext.fromXContent(parser));
} else if (SearchSourceBuilder.SCRIPT_FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
List<ScriptField> scriptFields = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
String scriptFieldName = parser.currentName();
token = parser.nextToken();
if (token == XContentParser.Token.START_OBJECT) {
Expand Down Expand Up @@ -740,12 +740,12 @@ public static TopHitsAggregationBuilder parse(String aggregationName, XContentPa
parser
);
} else if (SearchSourceBuilder.DOCVALUE_FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
FieldAndFormat ff = FieldAndFormat.fromXContent(parser);
factory.docValueField(ff.field, ff.format);
}
} else if (SearchSourceBuilder.FETCH_FIELDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
FieldAndFormat ff = FieldAndFormat.fromXContent(parser);
factory.fetchField(ff);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void writeTo(StreamOutput out) throws IOException {
*/
@Override
public final PipelineAggregator create() {
PipelineAggregator aggregator = createInternal(this.metadata);
return aggregator;
return createInternal(this.metadata);
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public final BucketMetricsPipelineAggregationBuilder<?> parse(String pipelineAgg
} else if (token == XContentParser.Token.START_ARRAY) {
if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
List<String> paths = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
String path = parser.text();
paths.add(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class InternalBucketMetricValue extends InternalNumericMetricsAggregation
public static final String NAME = "bucket_metric_value";
static final ParseField KEYS_FIELD = new ParseField("keys");

private double value;
private String[] keys;
private final double value;
private final String[] keys;

public InternalBucketMetricValue(String name, String[] keys, double value, DocValueFormat formatter, Map<String, Object> metadata) {
super(name, formatter, metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.util.Objects;

public class InternalPercentilesBucket extends InternalNumericMetricsAggregation.MultiValue implements PercentilesBucket {
private double[] percentiles;
private double[] percents;
private boolean keyed = true;
private final double[] percentiles;
private final double[] percents;
private final boolean keyed;

private final transient Map<Double, Double> percentileLookups = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class PercentilesBucketPipelineAggregator extends BucketMetricsPipelineAggregator {

private final double[] percents;
private boolean keyed = true;
private final boolean keyed;
private List<Double> data;

PercentilesBucketPipelineAggregator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.TransportVersion;
import org.elasticsearch.TransportVersions;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.search.DocValueFormat;
Expand Down Expand Up @@ -169,11 +170,11 @@ public static SerialDiffPipelineAggregationBuilder parse(String reducerName, XCo
} else if (token == XContentParser.Token.START_ARRAY) {
if (BUCKETS_PATH.match(currentFieldName, parser.getDeprecationHandler())) {
List<String> paths = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
String path = parser.text();
paths.add(path);
}
bucketsPaths = paths.toArray(new String[paths.size()]);
bucketsPaths = paths.toArray(Strings.EMPTY_ARRAY);
} else {
throw new ParsingException(
parser.getTokenLocation(),
Expand Down
Loading

0 comments on commit e825825

Please sign in to comment.