Skip to content

Commit caceb62

Browse files
committed
Skip precomputation when valuesSource is null
Signed-off-by: Michael Froh <froh@amazon.com>
1 parent 19a40cc commit caceb62

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

server/src/main/java/org/opensearch/search/aggregations/metrics/AvgAggregator.java

+13-15
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
package org.opensearch.search.aggregations.metrics;
3333

3434
import org.apache.lucene.index.LeafReaderContext;
35-
import org.apache.lucene.search.CollectionTerminatedException;
3635
import org.apache.lucene.search.DocIdSetIterator;
3736
import org.apache.lucene.search.ScoreMode;
3837
import org.apache.lucene.util.FixedBitSet;
@@ -104,23 +103,29 @@ public ScoreMode scoreMode() {
104103
}
105104

106105
@Override
107-
public LeafBucketCollector getLeafCollector(LeafReaderContext ctx, final LeafBucketCollector sub) throws IOException {
106+
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
108107
if (valuesSource == null) {
109-
return LeafBucketCollector.NO_OP_COLLECTOR;
108+
return false;
110109
}
111110
CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
112111
if (supportedStarTree != null) {
113112
if (parent != null && subAggregators.length == 0) {
114113
// If this a child aggregator, then the parent will trigger star-tree pre-computation.
115114
// Returning NO_OP_COLLECTOR explicitly because the getLeafCollector() are invoked starting from innermost aggregators
116-
return LeafBucketCollector.NO_OP_COLLECTOR;
115+
return true;
117116
}
118-
return getStarTreeLeafCollector(ctx, sub, supportedStarTree);
117+
precomputeLeafUsingStarTree(ctx, supportedStarTree);
118+
return true;
119119
}
120-
return getDefaultLeafCollector(ctx, sub);
120+
return false;
121121
}
122122

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+
124129
final BigArrays bigArrays = context.bigArrays();
125130
final SortedNumericDoubleValues values = valuesSource.doubleValues(ctx);
126131
final CompensatedSum kahanSummation = new CompensatedSum(0, 0);
@@ -154,8 +159,7 @@ public void collect(int doc, long bucket) throws IOException {
154159
};
155160
}
156161

157-
public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafBucketCollector sub, CompositeIndexFieldInfo starTree)
158-
throws IOException {
162+
private void precomputeLeafUsingStarTree(LeafReaderContext ctx, CompositeIndexFieldInfo starTree) throws IOException {
159163
StarTreeValues starTreeValues = StarTreeQueryHelper.getStarTreeValues(ctx, starTree);
160164
assert starTreeValues != null;
161165

@@ -200,12 +204,6 @@ public LeafBucketCollector getStarTreeLeafCollector(LeafReaderContext ctx, LeafB
200204

201205
sums.set(0, kahanSummation.value());
202206
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-
};
209207
}
210208

211209
@Override

server/src/main/java/org/opensearch/search/aggregations/metrics/MaxAggregator.java

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public ScoreMode scoreMode() {
106106

107107
@Override
108108
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
109+
if (valuesSource == null) {
110+
return false;
111+
}
109112
CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
110113
if (supportedStarTree != null) {
111114
if (parent != null && subAggregators.length == 0) {

server/src/main/java/org/opensearch/search/aggregations/metrics/MinAggregator.java

+3
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public ScoreMode scoreMode() {
106106

107107
@Override
108108
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
109+
if (valuesSource == null) {
110+
return false;
111+
}
109112
CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
110113
if (supportedStarTree != null) {
111114
if (parent != null && subAggregators.length == 0) {

server/src/main/java/org/opensearch/search/aggregations/metrics/SumAggregator.java

+3
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public ScoreMode scoreMode() {
9494

9595
@Override
9696
protected boolean tryPrecomputeAggregationForLeaf(LeafReaderContext ctx) throws IOException {
97+
if (valuesSource == null) {
98+
return false;
99+
}
97100
CompositeIndexFieldInfo supportedStarTree = getSupportedStarTree(this.context.getQueryShardContext());
98101
if (supportedStarTree != null) {
99102
if (parent != null && subAggregators.length == 0) {

0 commit comments

Comments
 (0)