Search in sources :

Example 11 with FilterQueryTree

use of com.linkedin.pinot.common.utils.request.FilterQueryTree in project pinot by linkedin.

the class FilterTreeOptimizationTest method testQuery.

/**
   * Helper method to perform the actual testing for the given query.
   * <ul>
   *   <li> Constructs the operator tree with and without alwaysFalse optimizations. </li>
   *   <li> Compares that all docIds filtered by the two operators are identical. </li>
   * </ul>
   * @param query Query to run.
   */
private void testQuery(String query) {
    BrokerRequest brokerRequest = _compiler.compileToBrokerRequest(query);
    FilterQueryTree filterQueryTree = RequestUtils.generateFilterQueryTree(brokerRequest);
    BaseFilterOperator expectedOperator = FilterPlanNode.constructPhysicalOperator(filterQueryTree, _indexSegment, false);
    BaseFilterOperator actualOperator = FilterPlanNode.constructPhysicalOperator(filterQueryTree, _indexSegment, true);
    BaseFilterBlock expectedBlock;
    while ((expectedBlock = expectedOperator.getNextBlock()) != null) {
        BaseFilterBlock actualBlock = actualOperator.getNextBlock();
        Assert.assertNotNull(actualBlock);
        final BlockDocIdSet expectedDocIdSet = expectedBlock.getBlockDocIdSet();
        final BlockDocIdIterator expectedIterator = expectedDocIdSet.iterator();
        final BlockDocIdSet actualDocIdSet = actualBlock.getBlockDocIdSet();
        final BlockDocIdIterator actualIterator = actualDocIdSet.iterator();
        int expectedDocId;
        int actualDocId;
        while (((expectedDocId = expectedIterator.next()) != Constants.EOF) && ((actualDocId = actualIterator.next()) != Constants.EOF)) {
            Assert.assertEquals(actualDocId, expectedDocId);
        }
        Assert.assertTrue(expectedIterator.next() == Constants.EOF);
        Assert.assertTrue(actualIterator.next() == Constants.EOF);
    }
}
Also used : BaseFilterOperator(com.linkedin.pinot.core.operator.filter.BaseFilterOperator) FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) BlockDocIdSet(com.linkedin.pinot.core.common.BlockDocIdSet) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest) BaseFilterBlock(com.linkedin.pinot.core.operator.blocks.BaseFilterBlock) BlockDocIdIterator(com.linkedin.pinot.core.common.BlockDocIdIterator)

Example 12 with FilterQueryTree

use of com.linkedin.pinot.common.utils.request.FilterQueryTree in project pinot by linkedin.

the class InPredicateAstNode method buildFilterQueryTree.

@Override
public FilterQueryTree buildFilterQueryTree() {
    if (_identifier == null) {
        throw new Pql2CompilationException("IN predicate has no identifier");
    }
    TreeSet<String> values = new TreeSet<>();
    for (AstNode astNode : getChildren()) {
        if (astNode instanceof LiteralAstNode) {
            LiteralAstNode node = (LiteralAstNode) astNode;
            values.add(node.getValueAsString());
        }
    }
    String[] valueArray = values.toArray(new String[values.size()]);
    FilterOperator filterOperator;
    if (_isNotInClause) {
        filterOperator = FilterOperator.NOT_IN;
    } else {
        filterOperator = FilterOperator.IN;
    }
    return new FilterQueryTree(_identifier, Collections.singletonList(StringUtil.join("\t\t", valueArray)), filterOperator, null);
}
Also used : FilterOperator(com.linkedin.pinot.common.request.FilterOperator) FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) TreeSet(java.util.TreeSet) Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException)

Example 13 with FilterQueryTree

use of com.linkedin.pinot.common.utils.request.FilterQueryTree in project pinot by linkedin.

the class ColumnValueSegmentPrunerTest method runPruner.

private boolean runPruner(String query) {
    BrokerRequest brokerRequest = COMPILER.compileToBrokerRequest(query);
    FilterQueryTree filterQueryTree = RequestUtils.generateFilterQueryTree(brokerRequest);
    return ColumnValueSegmentPruner.pruneSegment(filterQueryTree, COLUMN_METADATA_MAP);
}
Also used : FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) BrokerRequest(com.linkedin.pinot.common.request.BrokerRequest)

Example 14 with FilterQueryTree

use of com.linkedin.pinot.common.utils.request.FilterQueryTree in project pinot by linkedin.

the class SegmentQueryProcessor method process.

public ResultTable process(BrokerRequest brokerRequest) throws Exception {
    if (pruneSegment(brokerRequest)) {
        return null;
    }
    LOGGER.debug("Processing segment: {}", _segmentName);
    FilterQueryTree filterQueryTree = RequestUtils.generateFilterQueryTree(brokerRequest);
    List<Integer> filteredDocIds = filterDocIds(filterQueryTree, null);
    ResultTable result = null;
    if (brokerRequest.isSetAggregationsInfo()) {
        // Aggregation only
        if (!brokerRequest.isSetGroupBy()) {
            Aggregation aggregation = new Aggregation(_indexSegment, _metadata, filteredDocIds, brokerRequest.getAggregationsInfo(), null, 10);
            result = aggregation.run();
        } else {
            // Aggregation GroupBy
            GroupBy groupBy = brokerRequest.getGroupBy();
            Aggregation aggregation = new Aggregation(_indexSegment, _metadata, filteredDocIds, brokerRequest.getAggregationsInfo(), groupBy.getColumns(), groupBy.getTopN());
            result = aggregation.run();
        }
    } else {
        // Only Selection
        if (brokerRequest.isSetSelections()) {
            List<String> columns = brokerRequest.getSelections().getSelectionColumns();
            if (columns.contains("*")) {
                columns = Arrays.asList(_indexSegment.getColumnNames());
            }
            List<Pair> selectionColumns = new ArrayList<>();
            Set<String> columSet = new HashSet<>();
            // Collect a unique list of columns, in case input has duplicates.
            for (String column : columns) {
                if (!columSet.contains(column)) {
                    selectionColumns.add(new Pair(column, null));
                    columSet.add(column);
                }
            }
            Selection selection = new Selection(_indexSegment, _metadata, filteredDocIds, selectionColumns);
            result = selection.run();
        }
    }
    result.setNumDocsScanned(filteredDocIds.size());
    result.setTotalDocs(_totalDocs);
    return result;
}
Also used : GroupBy(com.linkedin.pinot.common.request.GroupBy) FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) ArrayList(java.util.ArrayList) Pair(com.linkedin.pinot.core.query.utils.Pair) HashSet(java.util.HashSet)

Example 15 with FilterQueryTree

use of com.linkedin.pinot.common.utils.request.FilterQueryTree in project pinot by linkedin.

the class SegmentQueryProcessor method filterDocIds.

private List<Integer> filterDocIds(FilterQueryTree filterQueryTree, List<Integer> inputDocIds) {
    // If no filter predicate, return the input without filtering.
    if (filterQueryTree == null) {
        List<Integer> allDocs = new ArrayList<>(_totalDocs);
        for (int i = 0; i < _totalDocs; ++i) {
            allDocs.add(i);
        }
        return allDocs;
    }
    final List<FilterQueryTree> childFilters = filterQueryTree.getChildren();
    final boolean isLeaf = (childFilters == null) || childFilters.isEmpty();
    if (isLeaf) {
        FilterOperator filterType = filterQueryTree.getOperator();
        String column = filterQueryTree.getColumn();
        final List<String> value = filterQueryTree.getValue();
        return getMatchingDocIds(inputDocIds, filterType, column, value);
    }
    List<Integer> result = filterDocIds(childFilters.get(0), inputDocIds);
    final FilterOperator operator = filterQueryTree.getOperator();
    for (int i = 1; i < childFilters.size(); ++i) {
        //      List<Integer> childResult = operator.equals(FilterOperator.AND) ? filterDocIds(childFilters.get(i), result)
        //          : filterDocIds(childFilters.get(i), inputDocIds);
        List<Integer> childResult = filterDocIds(childFilters.get(i), inputDocIds);
        result = combine(result, childResult, operator);
    }
    return result;
}
Also used : FilterOperator(com.linkedin.pinot.common.request.FilterOperator) FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) ArrayList(java.util.ArrayList)

Aggregations

FilterQueryTree (com.linkedin.pinot.common.utils.request.FilterQueryTree)24 BrokerRequest (com.linkedin.pinot.common.request.BrokerRequest)7 FilterOperator (com.linkedin.pinot.common.request.FilterOperator)6 ArrayList (java.util.ArrayList)5 Pql2Compiler (com.linkedin.pinot.pql.parsers.Pql2Compiler)4 BaseFilterOperator (com.linkedin.pinot.core.operator.filter.BaseFilterOperator)3 Test (org.testng.annotations.Test)3 GroupBy (com.linkedin.pinot.common.request.GroupBy)2 SegmentMetadata (com.linkedin.pinot.common.segment.SegmentMetadata)2 BitmapBasedFilterOperator (com.linkedin.pinot.core.operator.filter.BitmapBasedFilterOperator)2 EmptyFilterOperator (com.linkedin.pinot.core.operator.filter.EmptyFilterOperator)2 MatchEntireSegmentOperator (com.linkedin.pinot.core.operator.filter.MatchEntireSegmentOperator)2 ScanBasedFilterOperator (com.linkedin.pinot.core.operator.filter.ScanBasedFilterOperator)2 SortedInvertedIndexBasedFilterOperator (com.linkedin.pinot.core.operator.filter.SortedInvertedIndexBasedFilterOperator)2 ColumnMetadata (com.linkedin.pinot.core.segment.index.ColumnMetadata)2 Pql2CompilationException (com.linkedin.pinot.pql.parsers.Pql2CompilationException)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 FieldSpec (com.linkedin.pinot.common.data.FieldSpec)1