Search in sources :

Example 46 with ValueExpr

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;
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) Group(org.eclipse.rdf4j.query.algebra.Group) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) Filter(org.eclipse.rdf4j.query.algebra.Filter) Var(org.eclipse.rdf4j.query.algebra.Var) AggregateOperator(org.eclipse.rdf4j.query.algebra.AggregateOperator) GroupElem(org.eclipse.rdf4j.query.algebra.GroupElem) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem)

Example 47 with ValueExpr

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;
}
Also used : ListMemberOperator(org.eclipse.rdf4j.query.algebra.ListMemberOperator) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) ValueConstant(org.eclipse.rdf4j.query.algebra.ValueConstant) Compare(org.eclipse.rdf4j.query.algebra.Compare)

Example 48 with ValueExpr

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;
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) GroupConcat(org.eclipse.rdf4j.query.algebra.GroupConcat)

Example 49 with ValueExpr

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(")");
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr)

Example 50 with ValueExpr

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(")");
}
Also used : ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr)

Aggregations

ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)55 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)19 Var (org.eclipse.rdf4j.query.algebra.Var)19 ASTValueExpr (org.eclipse.rdf4j.query.parser.serql.ast.ASTValueExpr)14 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)10 ArrayList (java.util.ArrayList)9 Extension (org.eclipse.rdf4j.query.algebra.Extension)9 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)9 And (org.eclipse.rdf4j.query.algebra.And)7 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)7 Filter (org.eclipse.rdf4j.query.algebra.Filter)6 Projection (org.eclipse.rdf4j.query.algebra.Projection)6 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)6 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)6 List (java.util.List)5 Compare (org.eclipse.rdf4j.query.algebra.Compare)5 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)5 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)5 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)4 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)4