Skip to content

Commit f3f787e

Browse files
committed
fix flaky integration tests
Signed-off-by: Anthony Leong <[email protected]>
1 parent 3485432 commit f3f787e

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

server/src/main/java/org/opensearch/index/query/IntervalBuilder.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,20 @@ protected IntervalsSource analyzeTerm(TokenStream ts) throws IOException {
144144
return Intervals.term(BytesRef.deepCopyOf(bytesAtt.getBytesRef()));
145145
}
146146

147+
static boolean canCombineSources(List<IntervalsSource> sources) {
148+
int sourceIndex = 0;
149+
long disjunctionCount = 1;
150+
151+
while (sourceIndex < sources.size()) {
152+
disjunctionCount = disjunctionCount * sources.get(sourceIndex).pullUpDisjunctions().size();
153+
if (disjunctionCount > IndexSearcher.getMaxClauseCount()) {
154+
return false;
155+
}
156+
sourceIndex += 1;
157+
}
158+
return true;
159+
}
160+
147161
protected static IntervalsSource combineSources(List<IntervalsSource> sources, int maxGaps, IntervalMode mode) {
148162
if (sources.size() == 0) {
149163
return NO_INTERVALS;

server/src/main/java/org/opensearch/index/query/IntervalsSourceProvider.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,9 @@ public IntervalsSource getSource(QueryShardContext ctx, MappedFieldType fieldTyp
443443
for (IntervalsSourceProvider provider : subSources) {
444444
ss.add(provider.getSource(ctx, fieldType));
445445
}
446+
if (maxGaps == 0 && mode == IntervalMode.ORDERED && IntervalBuilder.canCombineSources(ss) == false) {
447+
throw new IllegalArgumentException("Too many disjunctions to expand");
448+
}
446449
IntervalsSource source = IntervalBuilder.combineSources(ss, maxGaps, mode);
447450
if (filter != null) {
448451
return filter.filter(source, ctx, fieldType);

test/framework/src/main/java/org/opensearch/test/AbstractQueryTestCase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,13 @@ public void testToQuery() throws IOException {
448448
* We do it this way in SearchService where
449449
* we first rewrite the query with a private context, then reset the context and then build the actual lucene query*/
450450
QueryBuilder rewritten = rewriteQuery(firstQuery, new QueryShardContext(context));
451-
Query firstLuceneQuery = rewritten.toQuery(context);
451+
Query firstLuceneQuery;
452+
try {
453+
firstLuceneQuery = rewritten.toQuery(context);
454+
} catch (IllegalArgumentException e) {
455+
assertEquals("Too many disjunctions to expand", e.getMessage());
456+
continue;
457+
}
452458
assertNotNull("toQuery should not return null", firstLuceneQuery);
453459
assertLuceneQuery(firstQuery, firstLuceneQuery, context);
454460
// remove after assertLuceneQuery since the assertLuceneQuery impl might access the context as well

0 commit comments

Comments
 (0)