Skip to content

Commit

Permalink
handle empty bitmap rewrite scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
  • Loading branch information
bowenlan-amzn committed Aug 8, 2024
1 parent 8e1feb0 commit c51dfc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.lucene.sandbox.document.HalfFloatPoint;
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.IndexOrDocValuesQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.IndexSortSortedNumericDocValuesRangeQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.PointInSetQuery;
Expand Down Expand Up @@ -1463,6 +1464,14 @@ public BytesRef next() {
return encoded;
}
}) {
@Override
public Query rewrite(IndexSearcher indexSearcher) throws IOException {
if (bitmap.isEmpty()) {
return new MatchNoDocsQuery();
}
return super.rewrite(indexSearcher);
}

@Override
protected String toString(byte[] value) {
assert value.length == Integer.BYTES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public class BitmapDocValuesQuery extends Query implements Accountable {
public BitmapDocValuesQuery(String field, RoaringBitmap bitmap) {
this.field = field;
this.bitmap = bitmap;
min = bitmap.first();
max = bitmap.last();
if (!bitmap.isEmpty()) {
min = bitmap.first();
max = bitmap.last();
} else {
min = 0; // final field
max = 0;
}
}

@Override
Expand Down Expand Up @@ -112,7 +117,7 @@ public String toString(String field) {

@Override
public Query rewrite(IndexSearcher indexSearcher) throws IOException {
if (bitmap.getLongCardinality() == 0) {
if (bitmap.isEmpty()) {
return new MatchNoDocsQuery();
}
return super.rewrite(indexSearcher);
Expand Down

0 comments on commit c51dfc8

Please sign in to comment.