From ff4d900a589327ee66d9766e93a96d8387d6d62e Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Tue, 7 Jan 2025 15:22:06 +0100 Subject: [PATCH] Remove some dead aggs code around delayed aggs (#119620) Looks like the removed classes never went anywhere => we should remove the dead code for the time being. --- .../bucket/BucketsAggregator.java | 7 -- .../bucket/DelayedBucketReducer.java | 87 ---------------- ...ongKeyedMultiBucketsAggregatorReducer.java | 98 ------------------- .../bucket/range/InternalBinaryRange.java | 7 -- 4 files changed, 199 deletions(-) delete mode 100644 server/src/main/java/org/elasticsearch/search/aggregations/bucket/DelayedBucketReducer.java delete mode 100644 server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/LongKeyedMultiBucketsAggregatorReducer.java diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java index e86c7127ec2f4..592f7b4887598 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/BucketsAggregator.java @@ -59,13 +59,6 @@ public BucketsAggregator( 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 maxBucketOrd buckets available. */ diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/DelayedBucketReducer.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/DelayedBucketReducer.java deleted file mode 100644 index 28b184797ce1e..0000000000000 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/DelayedBucketReducer.java +++ /dev/null @@ -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 { - - 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; - 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; - } -} diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/LongKeyedMultiBucketsAggregatorReducer.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/LongKeyedMultiBucketsAggregatorReducer.java deleted file mode 100644 index ccb4a7294e58d..0000000000000 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/histogram/LongKeyedMultiBucketsAggregatorReducer.java +++ /dev/null @@ -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 implements Releasable { - - private final AggregationReduceContext reduceContext; - private final int size; - private final long minDocCount; - private final LongObjectPagedHashMap> 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 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 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 get() { - reduceContext.consumeBucketsAndMaybeBreak(consumeBucketCount); - final List 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); - } -} diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java index 34a2ebea88440..740d53eb245e4 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/range/InternalBinaryRange.java @@ -271,13 +271,6 @@ public InternalAggregation finalizeSampling(SamplingContext samplingContext) { ); } - private Bucket reduceBucket(List buckets, AggregationReduceContext context) { - assert buckets.isEmpty() == false; - final List 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) {