use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.
the class TupleExprBuilder method processHavingClause.
private TupleExpr processHavingClause(ASTHavingClause havingNode, TupleExpr tupleExpr, Group group) throws VisitorException {
if (havingNode != null) {
// create an implicit group
if (group == null) {
group = new Group(tupleExpr);
}
ValueExpr expr = (ValueExpr) havingNode.jjtGetChild(0).jjtAccept(this, tupleExpr);
// retrieve any aggregate operators from the expression.
AggregateCollector collector = new AggregateCollector();
collector.meetOther(expr);
// replace operator occurrences with an anonymous var, and alias it
// to the group
Extension extension = new Extension();
for (AggregateOperator operator : collector.getOperators()) {
Var var = createAnonVar();
// replace occurrence of the operator in the filter expression
// with the variable.
AggregateOperatorReplacer replacer = new AggregateOperatorReplacer(operator, var);
replacer.meetOther(expr);
String alias = var.getName();
// create an extension linking the operator to the variable
// name.
ExtensionElem pe = new ExtensionElem(operator, alias);
extension.addElement(pe);
// add the aggregate operator to the group.
GroupElem ge = new GroupElem(alias, operator);
// FIXME quite often the aggregate in the HAVING clause will be
// a duplicate of an aggregate in the projection. We could
// perhaps
// optimize for that, to avoid having to evaluate twice.
group.addGroupElement(ge);
}
extension.setArg(group);
tupleExpr = new Filter(extension, expr);
}
return tupleExpr;
}
use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public ValueExpr visit(ASTIn node, Object data) throws VisitorException {
ValueExpr result = null;
ValueExpr leftArg = (ValueExpr) data;
int listItemCount = node.jjtGetNumChildren();
if (listItemCount == 0) {
result = new ValueConstant(BooleanLiteral.FALSE);
} else if (listItemCount == 1) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, null);
result = new Compare(leftArg, arg, CompareOp.EQ);
} else {
ListMemberOperator listMemberOperator = new ListMemberOperator();
listMemberOperator.addArgument(leftArg);
for (int i = 0; i < listItemCount; i++) {
ValueExpr arg = (ValueExpr) node.jjtGetChild(i).jjtAccept(this, null);
listMemberOperator.addArgument(arg);
}
result = listMemberOperator;
}
return result;
}
use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.
the class TupleExprBuilder method visit.
@Override
public Object visit(ASTGroupConcat node, Object data) throws VisitorException {
ValueExpr ve = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, data);
GroupConcat gc = new GroupConcat(ve, node.isDistinct());
if (node.jjtGetNumChildren() > 1) {
ValueExpr separator = (ValueExpr) node.jjtGetChild(1).jjtAccept(this, data);
gc.setSeparator(separator);
}
return gc;
}
use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.
the class SerqlValueExprRenderer method meet.
/**
* @inheritDoc
*/
@Override
public void meet(FunctionCall theOp) throws Exception {
mBuffer.append(theOp.getURI()).append("(");
boolean aFirst = true;
for (ValueExpr aArg : theOp.getArgs()) {
if (!aFirst) {
mBuffer.append(", ");
} else {
aFirst = false;
}
aArg.visit(this);
}
mBuffer.append(")");
}
use of org.eclipse.rdf4j.query.algebra.ValueExpr in project rdf4j by eclipse.
the class SparqlValueExprRenderer method meet.
/**
* @inheritDoc
*/
@Override
public void meet(FunctionCall theOp) throws Exception {
mBuffer.append("<").append(theOp.getURI()).append(">(");
boolean aFirst = true;
for (ValueExpr aArg : theOp.getArgs()) {
if (!aFirst) {
mBuffer.append(", ");
} else {
aFirst = false;
}
aArg.visit(this);
}
mBuffer.append(")");
}
Aggregations