use of com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator in project pinot by linkedin.
the class RealtimeSegmentTest method testMetricPredicateWithInvIdx.
@Test
public void testMetricPredicateWithInvIdx() throws Exception {
DataSource ds1 = segmentWithInvIdx.getDataSource("count");
List<String> rhs = new ArrayList<String>();
rhs.add("890662862");
Predicate predicate = new EqPredicate("count", rhs);
BitmapBasedFilterOperator op = new BitmapBasedFilterOperator(predicate, ds1, 0, segmentWithInvIdx.getRawDocumentCount() - 1);
Block b = op.nextBlock();
BlockDocIdIterator iterator = b.getBlockDocIdSet().iterator();
DataSource ds2 = segmentWithInvIdx.getDataSource("count");
BlockSingleValIterator blockValIterator = (BlockSingleValIterator) ds2.nextBlock().getBlockValueSet().iterator();
int docId = iterator.next();
int counter = 0;
while (docId != Constants.EOF) {
blockValIterator.skipTo(docId);
Assert.assertEquals(ds1.getDictionary().get(blockValIterator.nextIntVal()), 890662862);
docId = iterator.next();
counter++;
}
Assert.assertEquals(counter, 100000);
}
use of com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator in project pinot by linkedin.
the class RealtimeSegmentTest method testNoMatchFilteringMetricPredicateWithInvIdx.
@Test
public void testNoMatchFilteringMetricPredicateWithInvIdx() throws Exception {
DataSource ds1 = segmentWithInvIdx.getDataSource("count");
List<String> rhs = new ArrayList<String>();
rhs.add("890662862");
Predicate predicate = new NEqPredicate("count", rhs);
BitmapBasedFilterOperator op = new BitmapBasedFilterOperator(predicate, ds1, 0, segmentWithInvIdx.getRawDocumentCount() - 1);
Block b = op.nextBlock();
BlockDocIdIterator iterator = b.getBlockDocIdSet().iterator();
int counter = 0;
int docId = iterator.next();
while (docId != Constants.EOF) {
// shouldn't reach here.
Assert.assertTrue(false);
docId = iterator.next();
counter++;
}
Assert.assertEquals(counter, 0);
}
use of com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator in project pinot by linkedin.
the class FilterPlanNode method reorder.
/**
* Re orders operators, puts Sorted -> Inverted and then Raw scan. TODO: With Inverted, we can
* further optimize based on cardinality
* @param operators
*/
private static void reorder(List<BaseFilterOperator> operators) {
final Map<Operator, Integer> operatorPriorityMap = new HashMap<Operator, Integer>();
for (Operator operator : operators) {
Integer priority = Integer.MAX_VALUE;
if (operator instanceof SortedInvertedIndexBasedFilterOperator) {
priority = 0;
} else if (operator instanceof AndOperator) {
priority = 1;
} else if (operator instanceof BitmapBasedFilterOperator) {
priority = 2;
} else if (operator instanceof ScanBasedFilterOperator) {
priority = 3;
} else if (operator instanceof OrOperator) {
priority = 4;
}
operatorPriorityMap.put(operator, priority);
}
Comparator<? super Operator> comparator = new Comparator<Operator>() {
@Override
public int compare(Operator o1, Operator o2) {
return Integer.compare(operatorPriorityMap.get(o1), operatorPriorityMap.get(o2));
}
};
Collections.sort(operators, comparator);
}
use of com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator in project pinot by linkedin.
the class FilterPlanNode method constructPhysicalOperator.
/**
* Helper method to build the operator tree from the filter query tree.
* @param filterQueryTree
* @param segment Index segment
* @param optimizeAlwaysFalse Optimize isResultEmpty predicates
* @return Filter Operator created
*/
@VisibleForTesting
public static BaseFilterOperator constructPhysicalOperator(FilterQueryTree filterQueryTree, IndexSegment segment, boolean optimizeAlwaysFalse) {
BaseFilterOperator ret;
if (null == filterQueryTree) {
return new MatchEntireSegmentOperator(segment.getSegmentMetadata().getTotalRawDocs());
}
final List<FilterQueryTree> childFilters = filterQueryTree.getChildren();
final boolean isLeaf = (childFilters == null) || childFilters.isEmpty();
if (!isLeaf) {
int numChildrenAlwaysFalse = 0;
int numChildren = childFilters.size();
List<BaseFilterOperator> operators = new ArrayList<>();
final FilterOperator filterType = filterQueryTree.getOperator();
for (final FilterQueryTree query : childFilters) {
BaseFilterOperator childOperator = constructPhysicalOperator(query, segment, optimizeAlwaysFalse);
// Count number of always false children.
if (optimizeAlwaysFalse && childOperator.isResultEmpty()) {
numChildrenAlwaysFalse++;
// Early bailout for 'AND' as soon as one of the children always evaluates to false.
if (filterType == FilterOperator.AND) {
break;
}
}
operators.add(childOperator);
}
ret = buildNonLeafOperator(filterType, operators, numChildrenAlwaysFalse, numChildren, optimizeAlwaysFalse);
} else {
final FilterOperator filterType = filterQueryTree.getOperator();
final String column = filterQueryTree.getColumn();
Predicate predicate = Predicate.newPredicate(filterQueryTree);
DataSource ds;
ds = segment.getDataSource(column);
DataSourceMetadata dataSourceMetadata = ds.getDataSourceMetadata();
BaseFilterOperator baseFilterOperator;
int startDocId = 0;
//end is inclusive
int endDocId = segment.getSegmentMetadata().getTotalRawDocs() - 1;
if (dataSourceMetadata.hasInvertedIndex()) {
// range evaluation based on inv index is inefficient, so do this only if is NOT range.
if (!filterType.equals(FilterOperator.RANGE)) {
if (dataSourceMetadata.isSingleValue() && dataSourceMetadata.isSorted()) {
// if the column is sorted use sorted inverted index based implementation
baseFilterOperator = new SortedInvertedIndexBasedFilterOperator(predicate, ds, startDocId, endDocId);
} else {
baseFilterOperator = new BitmapBasedFilterOperator(predicate, ds, startDocId, endDocId);
}
} else {
baseFilterOperator = new ScanBasedFilterOperator(predicate, ds, startDocId, endDocId);
}
} else {
baseFilterOperator = new ScanBasedFilterOperator(predicate, ds, startDocId, endDocId);
}
ret = baseFilterOperator;
}
// If operator evaluates to false, then just return an empty operator.
if (ret.isResultEmpty()) {
ret = new EmptyFilterOperator();
}
return ret;
}
use of com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator in project pinot by linkedin.
the class RealtimeSegmentTest method testNoRangeMatchFilteringMetricPredicateWithInvIdx.
@Test
public void testNoRangeMatchFilteringMetricPredicateWithInvIdx() throws Exception {
DataSource ds1 = segmentWithInvIdx.getDataSource("count");
List<String> rhs = new ArrayList<String>();
rhs.add("[0\t\t100)");
Predicate predicate = new RangePredicate("count", rhs);
BitmapBasedFilterOperator op = new BitmapBasedFilterOperator(predicate, ds1, 0, segmentWithInvIdx.getRawDocumentCount() - 1);
Block b = op.nextBlock();
BlockDocIdIterator iterator = b.getBlockDocIdSet().iterator();
int counter = 0;
int docId = iterator.next();
while (docId != Constants.EOF) {
// shouldn't reach here.
Assert.assertTrue(false);
docId = iterator.next();
counter++;
}
Assert.assertEquals(counter, 0);
}
Aggregations