Skip to content

Commit ea6929e

Browse files
committed
Added check to not assert early termination in case of invalid field names
Signed-off-by: expani <anijainc@amazon.com>
1 parent 7a231e8 commit ea6929e

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

server/src/test/java/org/opensearch/search/aggregations/startree/MetricAggregatorTests.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.opensearch.index.mapper.MappedFieldType;
4242
import org.opensearch.index.mapper.MapperService;
4343
import org.opensearch.index.mapper.NumberFieldMapper;
44-
import org.opensearch.index.query.MatchAllQueryBuilder;
4544
import org.opensearch.index.query.QueryBuilder;
4645
import org.opensearch.index.query.QueryShardContext;
4746
import org.opensearch.index.query.TermQueryBuilder;
@@ -285,8 +284,7 @@ public void testStarTreeDocValues() throws IOException {
285284
);
286285

287286
// Test that feature parity is maintained for unmapped field names.
288-
sumAggregationBuilder = new SumAggregationBuilder("sumaggs").field("hello");
289-
queryBuilder = new MatchAllQueryBuilder();
287+
sumAggregationBuilder = sum("sumaggs").field("hello");
290288
testCase(
291289
indexSearcher,
292290
query,
@@ -295,7 +293,8 @@ public void testStarTreeDocValues() throws IOException {
295293
starTree,
296294
supportedDimensions,
297295
verifyAggregation(InternalSum::getValue),
298-
sumAggregationBuilder.build(queryShardContext, null)
296+
sumAggregationBuilder.build(queryShardContext, null),
297+
false // Invalid fields will return null Star Query Context which will not cause early termination for leaf collector
299298
);
300299

301300
ir.close();
@@ -319,7 +318,7 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
319318
List<Dimension> supportedDimensions,
320319
BiConsumer<V, V> verify
321320
) throws IOException {
322-
testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null);
321+
testCase(searcher, query, queryBuilder, aggBuilder, starTree, supportedDimensions, verify, null, true);
323322
}
324323

325324
private <T extends AggregationBuilder, V extends InternalAggregation> void testCase(
@@ -330,7 +329,8 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
330329
CompositeIndexFieldInfo starTree,
331330
List<Dimension> supportedDimensions,
332331
BiConsumer<V, V> verify,
333-
AggregatorFactory aggregatorFactory
332+
AggregatorFactory aggregatorFactory,
333+
boolean assertCollectorEarlyTermination
334334
) throws IOException {
335335
V starTreeAggregation = searchAndReduceStarTree(
336336
createIndexSettings(),
@@ -343,6 +343,7 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
343343
DEFAULT_MAX_BUCKETS,
344344
false,
345345
aggregatorFactory,
346+
assertCollectorEarlyTermination,
346347
DEFAULT_MAPPED_FIELD
347348
);
348349
V expectedAggregation = searchAndReduceStarTree(
@@ -356,6 +357,7 @@ private <T extends AggregationBuilder, V extends InternalAggregation> void testC
356357
DEFAULT_MAX_BUCKETS,
357358
false,
358359
aggregatorFactory,
360+
assertCollectorEarlyTermination,
359361
DEFAULT_MAPPED_FIELD
360362
);
361363
verify.accept(expectedAggregation, starTreeAggregation);

test/framework/src/main/java/org/opensearch/search/aggregations/AggregatorTestCase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ protected <A extends InternalAggregation, C extends Aggregator> A searchAndReduc
751751
int maxBucket,
752752
boolean hasNested,
753753
AggregatorFactory aggregatorFactory,
754+
boolean assertCollectorEarlyTermination,
754755
MappedFieldType... fieldTypes
755756
) throws IOException {
756757
query = query.rewrite(searcher);
@@ -782,7 +783,7 @@ protected <A extends InternalAggregation, C extends Aggregator> A searchAndReduc
782783
searcher.search(query, countingAggregator);
783784
countingAggregator.postCollection();
784785
aggs.add(countingAggregator.buildTopLevel());
785-
if (compositeIndexFieldInfo != null) {
786+
if (compositeIndexFieldInfo != null && assertCollectorEarlyTermination) {
786787
assertEquals(0, countingAggregator.collectCounter.get());
787788
}
788789

0 commit comments

Comments
 (0)