Skip to content

Commit

Permalink
Fix BitmapCollection::orCardinality API when combining a non-inverted…
Browse files Browse the repository at this point in the history
… bitmap with an inverted one (#14487)
  • Loading branch information
yashmayya authored Nov 19, 2024
1 parent 3fea2a2 commit c096c70
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,10 @@ public int orCardinality(BitmapCollection bitmaps) {
if (!bitmaps._inverted) {
return ImmutableRoaringBitmap.orCardinality(left, right);
}
return _numDocs - right.getCardinality() - ImmutableRoaringBitmap.andCardinality(left, right);
return _numDocs - right.getCardinality() + ImmutableRoaringBitmap.andCardinality(left, right);
} else {
if (!bitmaps._inverted) {
return _numDocs - left.getCardinality()
+ ImmutableRoaringBitmap.andCardinality(right, left);
return _numDocs - left.getCardinality() + ImmutableRoaringBitmap.andCardinality(right, left);
}
return _numDocs - ImmutableRoaringBitmap.andCardinality(left, right);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static Object[][] orCardinalityTestCases() {
},
{
10, ImmutableRoaringBitmap.bitmapOf(0, 5), false,
ImmutableRoaringBitmap.bitmapOf(0, 4), true, 7
ImmutableRoaringBitmap.bitmapOf(0, 4), true, 9
},
{
10, ImmutableRoaringBitmap.bitmapOf(0, 5), false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3762,4 +3762,19 @@ public void testFilteredAggregationWithNoValueMatchingAggregationFilterWithOptio
// empty groups
assertEquals(result.get("numRowsResultSet").asInt(), 0);
}

@Test(dataProvider = "useBothQueryEngines")
public void testFastFilteredCountWithOrFilterOnBitmapWithExclusiveBitmap(boolean useMultiStageQueryEngine)
throws Exception {
setUseMultiStageQueryEngine(useMultiStageQueryEngine);
// Column "Origin" has a range index, and column "DayofMonth" has a sorted index in several segments. This means
// that the count aggregation will be executed using the fast filtered count operator in these segments. The range
// index will produce a non-inverted bitmap collection and the sorted index will produce an inverted bitmap
// collection (since the filter predicate is exclusive).

// See this issue - https://github.com/apache/pinot/issues/14486
testQuery(
"SELECT COUNT(*) FROM mytable WHERE Origin BETWEEN 'ALB' AND 'LMT' OR DayofMonth <> 2"
);
}
}

0 comments on commit c096c70

Please sign in to comment.