use of io.mycat.hbt.parser.CallExpr in project Mycat2 by MyCATApache.
the class SchemaConvertor method aggregateCall.
public AggregateCall aggregateCall(ParseNode parseNode) {
CallExpr callExpr = (CallExpr) parseNode;
List<ParseNode> exprs = Collections.emptyList();
List<ParseNode> orderBy = new ArrayList<>();
ParseNode filter = null;
Boolean ignoreNulls = null;
Boolean approximate = null;
Boolean distinct = null;
String alias = null;
String name = null;
while (true) {
name = callExpr.getName();
exprs = callExpr.getArgs().getExprs();
if ("orderBy".equalsIgnoreCase(name)) {
orderBy.addAll(exprs.subList(1, exprs.size()));
callExpr = (CallExpr) exprs.get(0);
continue;
}
if ("filter".equalsIgnoreCase(name)) {
filter = exprs.get(1);
callExpr = (CallExpr) exprs.get(0);
continue;
}
if ("ignoreNulls".equalsIgnoreCase(name)) {
ignoreNulls = true;
callExpr = (CallExpr) exprs.get(0);
continue;
}
if ("approximate".equalsIgnoreCase(name)) {
approximate = true;
callExpr = (CallExpr) exprs.get(0);
continue;
}
if ("distinct".equalsIgnoreCase(name)) {
distinct = true;
callExpr = (CallExpr) exprs.get(0);
continue;
}
if ("alias".equalsIgnoreCase(name)) {
alias = exprs.get(1).toString();
callExpr = (CallExpr) exprs.get(0);
continue;
}
break;
}
List<Expr> collect = callExpr.getArgs().getExprs().stream().map(i -> transforExpr(i)).collect(Collectors.toList());
Expr filterExpr = null;
if (filter != null) {
filterExpr = transforExpr(filter);
}
return new AggregateCall(callExpr.getName(), alias, collect, distinct, approximate, ignoreNulls, filterExpr, orderBy.stream().map(i -> getOrderItem(i)).collect(Collectors.toList()));
}
use of io.mycat.hbt.parser.CallExpr in project Mycat2 by MyCATApache.
the class SchemaConvertor method values.
public List<Object> values(ParseNode fields) {
CallExpr callExpr = (CallExpr) fields;
List<ParseNode> exprs = callExpr.getArgs().getExprs();
return exprs.stream().map(i -> ((Literal) transforExpr(i)).getValue()).collect(Collectors.toList());
}
use of io.mycat.hbt.parser.CallExpr in project Mycat2 by MyCATApache.
the class SchemaConvertor method transforExpr.
public Expr transforExpr(ParseNode parseNode) {
if (parseNode instanceof CallExpr) {
CallExpr parseNode1 = (CallExpr) parseNode;
String name = parseNode1.getName();
List<ParseNode> exprs = parseNode1.getArgs().getExprs();
List<Expr> collect = exprs.stream().map(i -> transforExpr(i)).collect(Collectors.toList());
return new Fun(name, collect);
} else if (parseNode instanceof DecimalLiteral) {
return new Literal(((DecimalLiteral) parseNode).getNumber());
} else if (parseNode instanceof IdLiteral) {
return new Identifier(((IdLiteral) parseNode).getId());
} else if (parseNode instanceof StringLiteral) {
return new Literal(((StringLiteral) parseNode).getString());
} else if (parseNode instanceof IntegerLiteral) {
return new Literal(((IntegerLiteral) parseNode).getNumber());
} else if (parseNode instanceof ParenthesesExpr) {
ParenthesesExpr parseNode1 = (ParenthesesExpr) parseNode;
List<ParseNode> exprs = parseNode1.getExprs();
if (exprs.size() == 1) {
return transforExpr(exprs.get(0));
}
} else if (parseNode instanceof BooleanLiteral) {
return new Literal(((BooleanLiteral) parseNode).getValue());
} else if (parseNode instanceof NullLiteral) {
return new Literal(null);
} else if (parseNode instanceof ParamLiteral) {
if (params.isEmpty()) {
return new Param();
}
return new Literal(params.get(index++));
}
throw new UnsupportedOperationException();
}
Aggregations