|
32 | 32 | package org.opensearch.search.aggregations.metrics;
|
33 | 33 |
|
34 | 34 | import org.apache.lucene.index.LeafReaderContext;
|
35 |
| -import org.apache.lucene.search.CollectionTerminatedException; |
36 | 35 | import org.apache.lucene.search.DocIdSetIterator;
|
37 | 36 | import org.apache.lucene.search.ScoreMode;
|
38 | 37 | import org.apache.lucene.util.FixedBitSet;
|
@@ -104,23 +103,29 @@ public ScoreMode scoreMode() {
|
104 | 103 | }
|
105 | 104 |
|
106 | 105 | @Override
|
107 |
| - public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException { |
| 106 | + protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException { |
108 | 107 | if (valuesSource == null) {
|
109 |
| - return LeafBucketCollector.NO_OP_COLLECTOR; |
| 108 | + return false; |
110 | 109 | }
|
111 | 110 | CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
|
112 | 111 | if (supportedStarTree != null) {
|
113 | 112 | if (parent != null && subAggregators.length == 0) {
|
114 | 113 | // If this a child aggregator, then the parent will trigger star-tree pre-computation.
|
115 | 114 | // Returning NO_OP_COLLECTOR explicitly because the getLeafCollector() are invoked starting from innermost aggregators
|
116 |
| - return LeafBucketCollector.NO_OP_COLLECTOR; |
| 115 | + return true; |
117 | 116 | }
|
118 |
| - return getStarTreeLeafCollector(ctx, sub, supportedStarTree); |
| 117 | + precomputeLeafUsingStarTree(ctx, supportedStarTree); |
| 118 | + return true; |
119 | 119 | }
|
120 |
| - return getDefaultLeafCollector(ctx, sub); |
| 120 | + return false; |
121 | 121 | }
|
122 | 122 |
|
123 |
| - private LeafBucketCollector getDefaultLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub) throws IOException { |
| 123 | + @Override |
| 124 | + public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException { |
| 125 | + if (valuesSource == null) { |
| 126 | + return LeafBucketCollector.NO_OP_COLLECTOR; |
| 127 | + } |
| 128 | + |
124 | 129 | final BigArrays bigArrays = context.bigArrays();
|
125 | 130 | final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
|
126 | 131 | final CompensatedSum kahanSummation = new CompensatedSum(0, 0);
|
@@ -154,8 +159,7 @@ public void collect(int doc, long bucket) throws IOException {
|
154 | 159 | };
|
155 | 160 | }
|
156 | 161 |
|
157 |
| - public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub, CompositeIndexFieldInfo starTree) |
158 |
| - throws IOException { |
| 162 | + private void precomputeLeafUsingStarTree(LeafReaderContext ctx, CompositeIndexFieldInfo starTree) throws IOException { |
159 | 163 | StarTreeValues starTreeValues = StarTreeQueryHelper.getStarTreeValues(ctx, starTree);
|
160 | 164 | assert starTreeValues != null;
|
161 | 165 |
|
@@ -200,12 +204,6 @@ public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafB
|
200 | 204 |
|
201 | 205 | sums.set(0, kahanSummation.value());
|
202 | 206 | compensations.set(0, kahanSummation.delta());
|
203 |
| - return new LeafBucketCollectorBase(sub, valuesSource.doubleValues(ctx)) { |
204 |
| - @Override |
205 |
| - public void collect(int doc, long bucket) { |
206 |
| - throw new CollectionTerminatedException(); |
207 |
| - } |
208 |
| - }; |
209 | 207 | }
|
210 | 208 |
|
211 | 209 | @Override
|
|
0 commit comments