Ver Fonte

Remove some dead aggs code around delayed aggs (#119620) (#119654)

Looks like the removed classes never went anywhere => we should remove the dead code for the time being.
Armin Braun há 9 meses atrás
pai
commit
cb50da3843

+ 0 - 7
server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java

@@ -59,13 +59,6 @@ public abstract class BucketsAggregator extends AggregatorBase {
         docCountProvider = new DocCountProvider();
     }
 
-    /**
-     * Return an upper bound of the maximum bucket ordinal seen so far.
-     */
-    public final long maxBucketOrd() {
-        return docCounts.size();
-    }
-
     /**
      * Ensure there are at least <code>maxBucketOrd</code> buckets available.
      */

+ 0 - 87
server/src/main/java/org/elasticsearch/search/aggregations/bucket/DelayedBucketReducer.java

@@ -1,87 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the "Elastic License
- * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
- * Public License v 1"; you may not use this file except in compliance with, at
- * your election, the "Elastic License 2.0", the "GNU Affero General Public
- * License v3.0 only", or the "Server Side Public License, v 1".
- */
-
-package org.elasticsearch.search.aggregations.bucket;
-
-import org.elasticsearch.search.aggregations.AggregationReduceContext;
-import org.elasticsearch.search.aggregations.AggregatorsReducer;
-import org.elasticsearch.search.aggregations.InternalAggregations;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *  Class for reducing a list of {@link B} to a single {@link InternalAggregations}
- *  and the number of documents in a delayable fashion.
- *
- *  This class can be reused by calling {@link #reset(B)}.
- *
- * @see BucketReducer
- */
-public final class DelayedBucketReducer<B extends MultiBucketsAggregation.Bucket> {
-
-    private final AggregationReduceContext context;
-    // changes at reset time
-    private B proto;
-    // the maximum size of this array is the number of shards to be reduced. We currently do it in a batches of 256
-    // by default. if we expect bigger batches, we might consider to use ObjectArray.
-    private final List<InternalAggregations> internalAggregations;
-    private long count = 0;
-
-    public DelayedBucketReducer(B proto, AggregationReduceContext context) {
-        this.proto = proto;
-        this.context = context;
-        this.internalAggregations = new ArrayList<>();
-    }
-
-    /**
-     * Adds a {@link B} for reduction.
-     */
-    public void accept(B bucket) {
-        count += bucket.getDocCount();
-        internalAggregations.add(bucket.getAggregations());
-    }
-
-    /**
-     * returns the bucket prototype.
-     */
-    public B getProto() {
-        return proto;
-    }
-
-    /**
-     * Reset the content of this reducer.
-     */
-    public void reset(B proto) {
-        this.proto = proto;
-        count = 0L;
-        internalAggregations.clear();
-    }
-
-    /**
-     * returns the reduced {@link InternalAggregations}.
-     */
-    public InternalAggregations getAggregations() {
-        try (
-            AggregatorsReducer aggregatorsReducer = new AggregatorsReducer(proto.getAggregations(), context, internalAggregations.size())
-        ) {
-            for (InternalAggregations agg : internalAggregations) {
-                aggregatorsReducer.accept(agg);
-            }
-            return aggregatorsReducer.get();
-        }
-    }
-
-    /**
-     * returns the number of docs
-     */
-    public long getDocCount() {
-        return count;
-    }
-}

+ 0 - 98
server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/LongKeyedMultiBucketsAggregatorReducer.java

@@ -1,98 +0,0 @@
-/*
- * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
- * or more contributor license agreements. Licensed under the "Elastic License
- * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
- * Public License v 1"; you may not use this file except in compliance with, at
- * your election, the "Elastic License 2.0", the "GNU Affero General Public
- * License v3.0 only", or the "Server Side Public License, v 1".
- */
-package org.elasticsearch.search.aggregations.bucket.histogram;
-
-import org.elasticsearch.common.util.LongObjectPagedHashMap;
-import org.elasticsearch.core.Releasable;
-import org.elasticsearch.core.Releasables;
-import org.elasticsearch.search.aggregations.AggregationReduceContext;
-import org.elasticsearch.search.aggregations.InternalAggregations;
-import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation;
-import org.elasticsearch.search.aggregations.bucket.BucketReducer;
-import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *  Reduces aggregations where buckets are represented by a long key. It uses a {@link LongObjectPagedHashMap}
- *  to keep track of the different buckets.
- */
-abstract class LongKeyedMultiBucketsAggregatorReducer<B extends MultiBucketsAggregation.Bucket> implements Releasable {
-
-    private final AggregationReduceContext reduceContext;
-    private final int size;
-    private final long minDocCount;
-    private final LongObjectPagedHashMap<BucketReducer<B>> bucketsReducer;
-    int consumeBucketCount = 0;
-
-    LongKeyedMultiBucketsAggregatorReducer(AggregationReduceContext reduceContext, int size, long minDocCount) {
-        this.reduceContext = reduceContext;
-        this.size = size;
-        this.minDocCount = minDocCount;
-        bucketsReducer = new LongObjectPagedHashMap<>(size, reduceContext.bigArrays());
-    }
-
-    /**
-     * The bucket to reduce with its corresponding long key.
-     */
-    public final void accept(long key, B bucket) {
-        BucketReducer<B> reducer = bucketsReducer.get(key);
-        if (reducer == null) {
-            reducer = new BucketReducer<>(bucket, reduceContext, size);
-            bucketsReducer.put(key, reducer);
-        }
-        consumeBucketsAndMaybeBreak(reducer, bucket);
-        reducer.accept(bucket);
-    }
-
-    private void consumeBucketsAndMaybeBreak(BucketReducer<B> reducer, B bucket) {
-        if (reduceContext.isFinalReduce() == false || minDocCount == 0) {
-            if (reducer.getDocCount() == 0 && bucket.getDocCount() > 0) {
-                consumeBucketsAndMaybeBreak();
-            }
-        } else {
-            if (reducer.getDocCount() < minDocCount && (reducer.getDocCount() + bucket.getDocCount()) >= minDocCount) {
-                consumeBucketsAndMaybeBreak();
-            }
-        }
-    }
-
-    private void consumeBucketsAndMaybeBreak() {
-        if (consumeBucketCount++ >= InternalMultiBucketAggregation.REPORT_EMPTY_EVERY) {
-            reduceContext.consumeBucketsAndMaybeBreak(consumeBucketCount);
-            consumeBucketCount = 0;
-        }
-    }
-
-    /**
-     * Returns the reduced buckets.
-     */
-    public final List<B> get() {
-        reduceContext.consumeBucketsAndMaybeBreak(consumeBucketCount);
-        final List<B> reducedBuckets = new ArrayList<>((int) bucketsReducer.size());
-        bucketsReducer.forEach(entry -> {
-            if (reduceContext.isFinalReduce() == false || entry.value.getDocCount() >= minDocCount) {
-                reducedBuckets.add(createBucket(entry.key, entry.value.getDocCount(), entry.value.getAggregations()));
-            }
-        });
-        return reducedBuckets;
-    }
-
-    /**
-     * Builds a bucket provided the key, the number of documents and the sub-aggregations.
-     */
-    protected abstract B createBucket(long key, long docCount, InternalAggregations aggregations);
-
-    @Override
-    public final void close() {
-        bucketsReducer.forEach(r -> Releasables.close(r.value));
-        Releasables.close(bucketsReducer);
-    }
-}

+ 0 - 7
server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java

@@ -271,13 +271,6 @@ public final class InternalBinaryRange extends InternalMultiBucketAggregation<In
         );
     }
 
-    private Bucket reduceBucket(List<Bucket> buckets, AggregationReduceContext context) {
-        assert buckets.isEmpty() == false;
-        final List<InternalAggregations> aggregations = new BucketAggregationList<>(buckets);
-        final InternalAggregations aggs = InternalAggregations.reduce(aggregations, context);
-        return createBucket(aggs, buckets.get(0));
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         if (keyed) {