use of com.linkedin.pinot.core.operator.filter.EmptyFilterOperator in project pinot by linkedin.
the class FilterPlanNode method buildNonLeafOperator.
/**
* Helper method to build AND/OR operators.
* <ul>
* <li> Returns {@link EmptyFilterOperator} if at least on child always evaluates to false for AND. </li>
* <li> Returns {@link EmptyFilterOperator} if all children always evaluates to false for OR. </li>
* <li> Returns {@link AndOperator} or {@link OrOperator} based on filterType, otherwise. </li>
* </ul>
* @param filterType AND/OR
* @param nonFalseChildren Children that are not alwaysFalse.
* @param numChildrenAlwaysFalse Number of children that are always false.
* @param numChildren Total number of children.
* @param optimizeAlwaysFalse Optimize alwaysFalse predicates
* @return Filter Operator created
*/
private static BaseFilterOperator buildNonLeafOperator(FilterOperator filterType, List<BaseFilterOperator> nonFalseChildren, int numChildrenAlwaysFalse, int numChildren, boolean optimizeAlwaysFalse) {
BaseFilterOperator operator;
switch(filterType) {
case AND:
if (optimizeAlwaysFalse && numChildrenAlwaysFalse > 0) {
operator = new EmptyFilterOperator();
} else {
reorder(nonFalseChildren);
operator = new AndOperator(nonFalseChildren);
}
break;
case OR:
if (optimizeAlwaysFalse && numChildrenAlwaysFalse == numChildren) {
operator = new EmptyFilterOperator();
} else {
reorder(nonFalseChildren);
operator = new OrOperator(nonFalseChildren);
}
break;
default:
throw new UnsupportedOperationException("Not support filter type - " + filterType + " with children operators");
}
return operator;
}
use of com.linkedin.pinot.core.operator.filter.EmptyFilterOperator 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;
}
Aggregations