Skip to content

Commit

Permalink
iter
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase committed Nov 16, 2024
1 parent 213655c commit 33291b1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.LongArray;
import org.elasticsearch.common.util.ObjectArray;
import org.elasticsearch.common.util.concurrent.AtomicArray;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.IndexSettings;
Expand Down Expand Up @@ -670,8 +672,10 @@ public Aggregator subAggregator(String aggregatorName) {
}

@Override
public InternalAggregation[] buildAggregations(LongArray owningBucketOrds) {
return new InternalAggregation[] { buildEmptyAggregation() };
public ObjectArray<InternalAggregation> buildAggregations(LongArray owningBucketOrds) {
ObjectArray<InternalAggregation> agg = BigArrays.NON_RECYCLING_INSTANCE.newObjectArray(1);
agg.set(0, buildEmptyAggregation());
return agg;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected void doClose() {
}

@Override
public InternalAggregation[] buildAggregations(LongArray ordsToCollect) throws IOException {
public ObjectArray<InternalAggregation> buildAggregations(LongArray ordsToCollect) throws IOException {
try (ObjectArray<Bucket[]> topBucketsPerOrd = bigArrays().newObjectArray(ordsToCollect.size())) {
for (long ordIdx = 0; ordIdx < ordsToCollect.size(); ordIdx++) {
final long ord = ordsToCollect.get(ordIdx);
Expand All @@ -124,18 +124,17 @@ public InternalAggregation[] buildAggregations(LongArray ordsToCollect) throws I
topBucketsPerOrd.set(ordIdx, categorizer.toOrderedBuckets(size));
}
buildSubAggsForAllBuckets(topBucketsPerOrd, Bucket::getBucketOrd, Bucket::setAggregations);
InternalAggregation[] results = new InternalAggregation[Math.toIntExact(ordsToCollect.size())];
for (int ordIdx = 0; ordIdx < results.length; ordIdx++) {
results[ordIdx] = new InternalCategorizationAggregation(
return buildAggregations(
ordsToCollect.size(),
ordIdx -> new InternalCategorizationAggregation(
name,
bucketCountThresholds.getRequiredSize(),
bucketCountThresholds.getMinDocCount(),
similarityThreshold,
metadata(),
Arrays.asList(topBucketsPerOrd.get(ordIdx))
);
}
return results;
)
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.LongArray;
import org.elasticsearch.common.util.LongObjectPagedHashMap;
import org.elasticsearch.common.util.ObjectArray;
import org.elasticsearch.core.Releasables;
import org.elasticsearch.core.Tuple;
import org.elasticsearch.index.query.QueryBuilder;
Expand Down Expand Up @@ -118,13 +119,8 @@ public InternalAggregation buildEmptyAggregation() {
}

@Override
public final InternalAggregation[] buildAggregations(LongArray owningBucketOrds) throws IOException {
InternalAggregation[] results = new InternalAggregation[Math.toIntExact(owningBucketOrds.size())];
for (int ordIdx = 0; ordIdx < results.length; ordIdx++) {
results[ordIdx] = buildAggregation(ordIdx);
}

return results;
public final ObjectArray<InternalAggregation> buildAggregations(LongArray owningBucketOrds) throws IOException {
return buildAggregations(owningBucketOrds.size(), this::buildAggregation);
}

@Override
Expand Down

0 comments on commit 33291b1

Please sign in to comment.