Skip to content

Commit

Permalink
Optimize UnsignedLong range queries to convert to MatchNoDocsQuery wh…
Browse files Browse the repository at this point in the history
…en lower > upper bounds (opensearch-project#14416) (opensearch-project#14483)

* Added check for lower > upper at end of function

* Fixed mistake of using < operator on BigInteger, now using compareTo

* Fixed simple mistake of flipping > operator

* Fixed space formatting

* Updated CHANGELOG.md

* Issue number linked in CHANGELOG.md

* doTestDocValueRangeQueries now accepts MatchNoDocsQuery alongside IndexOrDocValuesQuery

* dotestdoTestDocValueRangeQueries only checks indexQuery and randomAccessQuery only when query is type IndexIndexOrDocValuesQuery

* Ran gradlew spotlessApply to fix import formatting issues

* Imported Matchers.either method instead of entire Matchers class

---------

(cherry picked from commit d2c08b3)

Signed-off-by: Skyring100 <106502383+Skyring100@users.noreply.github.com>
Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
Co-authored-by: Andriy Redko <andriy.redko@aiven.io>
Signed-off-by: kkewwei <kkewwei@163.com>
  • Loading branch information
2 people authored and kkewwei committed Jul 24, 2024
1 parent 3416781 commit 1bd21fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Bump `opentelemetry` from 1.36.0 to 1.39.0 ([#14457](https://github.com/opensearch-project/OpenSearch/pull/14457))

### Changed
- unsignedLongRangeQuery now returns MatchNoDocsQuery if the lower bounds are greater than the upper bounds ([#14416](https://github.com/opensearch-project/OpenSearch/pull/14416))
- Make the class CommunityIdProcessor final ([#14448](https://github.com/opensearch-project/OpenSearch/pull/14448))
- Updated the `indices.query.bool.max_clause_count` setting from being static to dynamically updateable ([#13568](https://github.com/opensearch-project/OpenSearch/pull/13568))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,9 @@ public static Query unsignedLongRangeQuery(
u = u.subtract(BigInteger.ONE);
}
}
if (l.compareTo(u) > 0) {
return new MatchNoDocsQuery();
}
return builder.apply(l, u);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import java.util.function.Supplier;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.either;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;

Expand Down Expand Up @@ -673,9 +674,11 @@ public void doTestDocValueRangeQueries(NumberType type, Supplier<Number> valueSu
true,
MOCK_QSC
);
assertThat(query, instanceOf(IndexOrDocValuesQuery.class));
IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) query;
assertEquals(searcher.count(indexOrDvQuery.getIndexQuery()), searcher.count(indexOrDvQuery.getRandomAccessQuery()));
assertThat(query, either(instanceOf(IndexOrDocValuesQuery.class)).or(instanceOf(MatchNoDocsQuery.class)));
if (query instanceof IndexOrDocValuesQuery) {
IndexOrDocValuesQuery indexOrDvQuery = (IndexOrDocValuesQuery) query;
assertEquals(searcher.count(indexOrDvQuery.getIndexQuery()), searcher.count(indexOrDvQuery.getRandomAccessQuery()));
}
}
reader.close();
dir.close();
Expand Down

0 comments on commit 1bd21fb

Please sign in to comment.