From 73d4fabe1ab4f1ecfc080ef16939135ff3740f13 Mon Sep 17 00:00:00 2001 From: Ignacio Vera Date: Thu, 5 Dec 2024 11:32:12 +0100 Subject: [PATCH] blind --- .../countedterms/CountedTermsAggregator.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/countedterms/CountedTermsAggregator.java b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/countedterms/CountedTermsAggregator.java index 5c4b4223027bc..571ce3a9a4519 100644 --- a/server/src/main/java/org/elasticsearch/search/aggregations/bucket/countedterms/CountedTermsAggregator.java +++ b/server/src/main/java/org/elasticsearch/search/aggregations/bucket/countedterms/CountedTermsAggregator.java @@ -40,7 +40,6 @@ import java.util.Arrays; import java.util.Map; import java.util.function.BiConsumer; -import java.util.function.Supplier; import static java.util.Collections.emptyList; import static org.elasticsearch.search.aggregations.InternalOrder.isKeyOrder; @@ -127,7 +126,7 @@ public InternalAggregation[] buildAggregations(LongArray owningBucketOrds) throw } try (LongArray ordsArray = bigArrays().newLongArray(ordsToCollect)) { long ordsCollected = 0; - for (long ordIdx = 0; ordIdx < topBucketsPerOrd.size(); ordIdx++) { + for (long ordIdx = 0; ordIdx < owningBucketOrds.size(); ordIdx++) { // as users can't control sort order, in practice we'll always sort by doc count descending try ( BucketPriorityQueue ordered = new BucketPriorityQueue<>( @@ -138,20 +137,12 @@ public InternalAggregation[] buildAggregations(LongArray owningBucketOrds) throw ) { BucketAndOrd spare = null; BytesKeyedBucketOrds.BucketOrdsEnum ordsEnum = bucketOrds.ordsEnum(owningBucketOrds.get(ordIdx)); - Supplier emptyBucketBuilder = () -> new StringTerms.Bucket( - new BytesRef(), - 0, - null, - false, - 0, - format - ); while (ordsEnum.next()) { long docCount = bucketDocCount(ordsEnum.ord()); otherDocCounts.increment(ordIdx, docCount); if (spare == null) { checkRealMemoryCBForInternalBucket(); - spare = new BucketAndOrd<>(emptyBucketBuilder.get()); + spare = new BucketAndOrd<>(new StringTerms.Bucket(new BytesRef(), 0, null, false, 0, format)); } ordsEnum.readValue(spare.bucket.getTermBytes()); spare.bucket.setDocCount(docCount); @@ -160,11 +151,12 @@ public InternalAggregation[] buildAggregations(LongArray owningBucketOrds) throw } final int orderedSize = (int) ordered.size(); final StringTerms.Bucket[] buckets = new StringTerms.Bucket[orderedSize]; - for (int i = (int) ordered.size() - 1; i >= 0; --i) { + for (int i = orderedSize - 1; i >= 0; --i) { BucketAndOrd bucketAndOrd = ordered.pop(); buckets[i] = bucketAndOrd.bucket; ordsArray.set(ordsCollected + i, bucketAndOrd.ord); otherDocCounts.increment(ordIdx, -bucketAndOrd.bucket.getDocCount()); + bucketAndOrd.bucket.setTermBytes(BytesRef.deepCopyOf(bucketAndOrd.bucket.getTermBytes())); } topBucketsPerOrd.set(ordIdx, buckets); ordsCollected += orderedSize;