Search in sources :

Example 1 with Pql2CompilationException

use of com.linkedin.pinot.pql.parsers.Pql2CompilationException in project pinot by linkedin.

the class BetweenPredicateAstNode method buildFilterQueryTree.

@Override
public FilterQueryTree buildFilterQueryTree() {
    if (getChildren().size() == 2) {
        try {
            LiteralAstNode left = (LiteralAstNode) getChildren().get(0);
            LiteralAstNode right = (LiteralAstNode) getChildren().get(1);
            return new FilterQueryTree(_identifier, Collections.singletonList("[" + left.getValueAsString() + "\t\t" + right.getValueAsString() + "]"), FilterOperator.RANGE, null);
        } catch (ClassCastException e) {
            throw new Pql2CompilationException("BETWEEN clause was expecting two literal AST nodes, got " + getChildren().get(0) + " and " + getChildren().get(1));
        }
    } else {
        throw new Pql2CompilationException("BETWEEN clause does not have two children nodes");
    }
}
Also used : FilterQueryTree(com.linkedin.pinot.common.utils.request.FilterQueryTree) Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException)

Example 2 with Pql2CompilationException

use of com.linkedin.pinot.pql.parsers.Pql2CompilationException in project pinot by linkedin.

the class FunctionCallAstNode method buildAggregationInfo.

public AggregationInfo buildAggregationInfo() {
    String identifier = null;
    for (AstNode astNode : getChildren()) {
        if (astNode instanceof IdentifierAstNode) {
            IdentifierAstNode node = (IdentifierAstNode) astNode;
            if (identifier == null) {
                identifier = node.getName();
            } else {
                throw new Pql2CompilationException("More than one identifier specified to an aggregation function");
            }
        } else if (astNode instanceof StarExpressionAstNode) {
            identifier = "*";
        } else if (astNode instanceof StringLiteralAstNode) {
            // Pinot quirk: Passing a string as an aggregation function is probably a column name
            StringLiteralAstNode node = (StringLiteralAstNode) astNode;
            identifier = node.getText();
        } else {
            throw new Pql2CompilationException("Child node of aggregation function is not an identifier, star or string literal.");
        }
    }
    String function = _name;
    // Pinot quirk: count is always count(*) no matter what
    if ("count".equalsIgnoreCase(function)) {
        function = "count";
        identifier = "*";
    }
    AggregationInfo aggregationInfo = new AggregationInfo();
    aggregationInfo.setAggregationType(function);
    aggregationInfo.putToAggregationParams("column", identifier);
    return aggregationInfo;
}
Also used : Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException) AggregationInfo(com.linkedin.pinot.common.request.AggregationInfo)

Example 3 with Pql2CompilationException

use of com.linkedin.pinot.pql.parsers.Pql2CompilationException in project pinot by linkedin.

the class OrderByAstNode method updateBrokerRequest.

@Override
public void updateBrokerRequest(BrokerRequest brokerRequest) {
    Selection selections = brokerRequest.getSelections();
    for (AstNode astNode : getChildren()) {
        if (astNode instanceof OrderByExpressionAstNode) {
            OrderByExpressionAstNode node = (OrderByExpressionAstNode) astNode;
            SelectionSort elem = new SelectionSort();
            elem.setColumn(node.getColumn());
            elem.setIsAsc("asc".equalsIgnoreCase(node.getOrdering()));
            selections.addToSelectionSortSequence(elem);
        } else {
            throw new Pql2CompilationException("Child node of ORDER BY node is not an expression node");
        }
    }
}
Also used : Selection(com.linkedin.pinot.common.request.Selection) SelectionSort(com.linkedin.pinot.common.request.SelectionSort) Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException)

Example 4 with Pql2CompilationException

use of com.linkedin.pinot.pql.parsers.Pql2CompilationException 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 5 with Pql2CompilationException

use of com.linkedin.pinot.pql.parsers.Pql2CompilationException in project pinot by linkedin.

the class OutputColumnAstNode method updateBrokerRequest.

@Override
public void updateBrokerRequest(BrokerRequest brokerRequest) {
    for (AstNode astNode : getChildren()) {
        // If the column is a function call, it must be an aggregation function
        if (astNode instanceof FunctionCallAstNode) {
            FunctionCallAstNode node = (FunctionCallAstNode) astNode;
            brokerRequest.addToAggregationsInfo(node.buildAggregationInfo());
        } else if (astNode instanceof IdentifierAstNode) {
            Selection selection = brokerRequest.getSelections();
            if (selection == null) {
                selection = new Selection();
                brokerRequest.setSelections(selection);
            }
            IdentifierAstNode node = (IdentifierAstNode) astNode;
            selection.addToSelectionColumns(node.getName());
        } else {
            throw new Pql2CompilationException("Output column is neither a function nor an identifier");
        }
    }
}
Also used : Selection(com.linkedin.pinot.common.request.Selection) Pql2CompilationException(com.linkedin.pinot.pql.parsers.Pql2CompilationException)

Aggregations

Pql2CompilationException (com.linkedin.pinot.pql.parsers.Pql2CompilationException)6 Selection (com.linkedin.pinot.common.request.Selection)2 FilterQueryTree (com.linkedin.pinot.common.utils.request.FilterQueryTree)2 AggregationInfo (com.linkedin.pinot.common.request.AggregationInfo)1 FilterOperator (com.linkedin.pinot.common.request.FilterOperator)1 SelectionSort (com.linkedin.pinot.common.request.SelectionSort)1 TreeSet (java.util.TreeSet)1