Skip to content

Commit

Permalink
Stop capturing the BucketAggregator when building internal sub-aggreg…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
iverase committed Jan 25, 2024
1 parent 4e91d69 commit 8e8b599
Showing 1 changed file with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,22 +180,31 @@ protected final InternalAggregations[] buildSubAggsForBuckets(long[] bucketOrdsT
}
InternalAggregations[] result = new InternalAggregations[bucketOrdsToCollect.length];
for (int ord = 0; ord < bucketOrdsToCollect.length; ord++) {
final int thisOrd = ord;
result[ord] = InternalAggregations.from(new AbstractList<>() {
@Override
public InternalAggregation get(int index) {
return aggregations[index][thisOrd];
}

@Override
public int size() {
return aggregations.length;
}
});
result[ord] = InternalAggregations.from(new InternalAggregationList(aggregations, ord));
}
return result;
}

private static class InternalAggregationList extends AbstractList<InternalAggregation> {
private final InternalAggregation[][] aggregations;
private final int ord;

private InternalAggregationList(InternalAggregation[][] aggregations, int ord) {
this.aggregations = aggregations;
this.ord = ord;
}

@Override
public InternalAggregation get(int index) {
return aggregations[index][ord];
}

@Override
public int size() {
return aggregations.length;
}
}

/**
* Build the sub aggregation results for a list of buckets and set them on
* the buckets. This is usually used by aggregations that are selective
Expand Down

0 comments on commit 8e8b599

Please sign in to comment.