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");
}
}
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;
}
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");
}
}
}
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);
}
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");
}
}
}
Aggregations