Search in sources :

Example 11 with ExtensionElem

use of org.eclipse.rdf4j.query.algebra.ExtensionElem in project rdf4j by eclipse.

the class TupleExprBuilder method visit.

@Override
public Object visit(ASTBind node, Object data) throws VisitorException {
    // bind expression
    ValueExpr ve = (ValueExpr) node.jjtGetChild(0).jjtAccept(this, data);
    // name to bind the expression outcome to
    Node aliasNode = node.jjtGetChild(1);
    String alias = ((ASTVar) aliasNode).getName();
    Extension extension = new Extension();
    extension.addElement(new ExtensionElem(ve, alias));
    TupleExpr result = null;
    TupleExpr arg = graphPattern.buildTupleExpr();
    // check if alias is not previously used.
    if (arg.getBindingNames().contains(alias)) {
        // SES-2314 we need to doublecheck that the reused varname is not
        // just
        // for an anonymous var or a constant.
        VarCollector collector = new VarCollector();
        arg.visit(collector);
        for (Var v : collector.getCollectedVars()) {
            if (alias.equals(v.getName())) {
                if (!v.isConstant() && !v.isAnonymous()) {
                    throw new VisitorException(String.format("BIND clause alias '%s' was previously used", alias));
                }
                break;
            }
        }
    }
    if (arg instanceof Filter) {
        result = arg;
        // the BIND expression.
        while (((Filter) arg).getArg() instanceof Filter) {
            arg = ((Filter) arg).getArg();
        }
        extension.setArg(((Filter) arg).getArg());
        ((Filter) arg).setArg(extension);
    } else {
        extension.setArg(arg);
        result = extension;
    }
    GraphPattern replacementGP = new GraphPattern(graphPattern);
    replacementGP.addRequiredTE(result);
    graphPattern = replacementGP;
    return result;
}
Also used : Extension(org.eclipse.rdf4j.query.algebra.Extension) ValueExpr(org.eclipse.rdf4j.query.algebra.ValueExpr) Filter(org.eclipse.rdf4j.query.algebra.Filter) Var(org.eclipse.rdf4j.query.algebra.Var) QueryModelNode(org.eclipse.rdf4j.query.algebra.QueryModelNode) IsBNode(org.eclipse.rdf4j.query.algebra.IsBNode) ExtensionElem(org.eclipse.rdf4j.query.algebra.ExtensionElem) TupleExpr(org.eclipse.rdf4j.query.algebra.TupleExpr)

Aggregations

Extension (org.eclipse.rdf4j.query.algebra.Extension)11 ExtensionElem (org.eclipse.rdf4j.query.algebra.ExtensionElem)11 Var (org.eclipse.rdf4j.query.algebra.Var)10 ValueExpr (org.eclipse.rdf4j.query.algebra.ValueExpr)9 ProjectionElemList (org.eclipse.rdf4j.query.algebra.ProjectionElemList)8 TupleExpr (org.eclipse.rdf4j.query.algebra.TupleExpr)8 ProjectionElem (org.eclipse.rdf4j.query.algebra.ProjectionElem)7 MultiProjection (org.eclipse.rdf4j.query.algebra.MultiProjection)6 Projection (org.eclipse.rdf4j.query.algebra.Projection)6 ArrayList (java.util.ArrayList)5 Reduced (org.eclipse.rdf4j.query.algebra.Reduced)5 Distinct (org.eclipse.rdf4j.query.algebra.Distinct)4 StatementPattern (org.eclipse.rdf4j.query.algebra.StatementPattern)4 ValueConstant (org.eclipse.rdf4j.query.algebra.ValueConstant)4 AggregateOperator (org.eclipse.rdf4j.query.algebra.AggregateOperator)3 BNodeGenerator (org.eclipse.rdf4j.query.algebra.BNodeGenerator)3 EmptySet (org.eclipse.rdf4j.query.algebra.EmptySet)3 Filter (org.eclipse.rdf4j.query.algebra.Filter)3 Group (org.eclipse.rdf4j.query.algebra.Group)3 GroupElem (org.eclipse.rdf4j.query.algebra.GroupElem)3