Search in sources :

Example 6 with ExprList

use of org.apache.jena.sparql.expr.ExprList in project jena by apache.

the class TransformFilterPlacement method placePropertyFunctionProcedure.

private Placement placePropertyFunctionProcedure(ExprList exprsIn, Set<Var> varScope, Op1 op) {
    ExprList exprListPlaceable = new ExprList();
    ExprList exprListRetain = new ExprList();
    for (Expr expr : exprsIn) {
        Set<Var> mentioned = expr.getVarsMentioned();
        if (Collections.disjoint(varScope, mentioned))
            exprListPlaceable.add(expr);
        else
            exprListRetain.add(expr);
    }
    if (!exprListPlaceable.isEmpty()) {
        Placement p = transform(exprListPlaceable, op.getSubOp());
        if (isNoChange(p))
            return resultNoChange(op);
        Op newOp = op.copy(p.op);
        p.unplaced.addAll(exprListRetain);
        return result(newOp, p.unplaced);
    }
    return resultNoChange(op);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) Var(org.apache.jena.sparql.core.Var)

Example 7 with ExprList

use of org.apache.jena.sparql.expr.ExprList in project jena by apache.

the class TransformFilterPlacement method placeProject.

private Placement placeProject(ExprList exprs, OpProject input) {
    Collection<Var> varsProject = input.getVars();
    ExprList pushed = new ExprList();
    ExprList unpushed = new ExprList();
    for (Expr expr : exprs) {
        Set<Var> exprVars = expr.getVarsMentioned();
        if (varsProject.containsAll(exprVars))
            pushed.add(expr);
        else
            unpushed.add(expr);
    }
    if (pushed.isEmpty())
        return resultNoChange(input);
    // (filter (project ...)) ===> (project (filter ...)) 
    return processSubOp1(pushed, unpushed, input);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) Var(org.apache.jena.sparql.core.Var)

Example 8 with ExprList

use of org.apache.jena.sparql.expr.ExprList in project jena by apache.

the class TransformFilterPlacement method placeUnion.

private Placement placeUnion(ExprList exprs, OpUnion input) {
    if (false) {
        // Push into both sides without thinking.
        // Left as a safety fallback.
        Op left = input.getLeft();
        Placement pLeft = transform(exprs, left);
        Op right = input.getRight();
        Placement pRight = transform(exprs, right);
        if (pLeft != null && !pLeft.unplaced.isEmpty())
            return noChangePlacement;
        if (pRight != null && !pRight.unplaced.isEmpty())
            return noChangePlacement;
        // Must be guarded by the above.
        left = transformOpAlways(exprs, left);
        right = transformOpAlways(exprs, right);
        Op op2 = OpUnion.create(left, right);
        return result(op2, emptyList);
    }
    Op left = input.getLeft();
    Placement pLeft = transform(exprs, left);
    Op right = input.getRight();
    Placement pRight = transform(exprs, right);
    // If it's placed in neither arm it should be passed back out for placement.
    //
    // If it's done in both arms, then expression can be left pushed in
    // and not passed back out for placement.
    // If it is done in one arm and not the other, then it can be left pushed
    // in but needs to be redone for the other arm as if it were no placed at all.
    // A filter applied twice is safe.
    ExprList exprs2 = null;
    for (Expr expr : exprs) {
        boolean unplacedLeft = (isNoChange(pLeft) || pLeft.unplaced.getList().contains(expr));
        boolean unplacedRight = (isNoChange(pRight) || pRight.unplaced.getList().contains(expr));
        //            if ( unplacedLeft && unplacedRight ) {
        //                System.out.println("Unplaced:     "+expr) ;
        //            } else if ( unplacedLeft ) {
        //                System.out.println("Unplaced(L):  "+expr) ;
        //            } else if ( unplacedRight ) {
        //                System.out.println("Unplaced(R):  "+expr) ;
        //            } else
        //                System.out.println("Placed(L+R):  "+expr) ;
        boolean placed = !unplacedLeft && !unplacedRight;
        if (placed)
            // Went into both arms - expression has been handled completely.
            continue;
        if (exprs2 == null)
            exprs2 = new ExprList();
        exprs2.add(expr);
    }
    Op newLeft = (pLeft == null) ? left : pLeft.op;
    Op newRight = (pRight == null) ? right : pRight.op;
    if (exprs2 == null)
        exprs2 = emptyList;
    //Op op2 = OpUnion.create(newLeft, newRight) ;
    Op op2 = input.copy(newLeft, newRight);
    return result(op2, exprs2);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList)

Example 9 with ExprList

use of org.apache.jena.sparql.expr.ExprList in project jena by apache.

the class AbstractTestJoin method testJoin.

protected void testJoin(String var, Table left, Table right, String conditions, Table tableOut) {
    JoinKey joinKey;
    if (var != null) {
        if (var.startsWith("?"))
            var = var.substring(1);
        joinKey = JoinKey.create(Var.alloc(var));
    } else {
        // No vars in join key.  Allow implementation to decide
        // if needed.  Join keys are only needed for hash join
        // (and related algorithms).
        joinKey = null;
    }
    ExprList exprs = null;
    if (conditions != null)
        exprs = SSE.parseExprList(conditions);
    executeTest(joinKey, left, right, exprs, tableOut);
}
Also used : ExprList(org.apache.jena.sparql.expr.ExprList)

Example 10 with ExprList

use of org.apache.jena.sparql.expr.ExprList in project jena by apache.

the class OpExecutor method execute.

protected QueryIterator execute(OpFilter opFilter, QueryIterator input) {
    ExprList exprs = opFilter.getExprs();
    Op base = opFilter.getSubOp();
    QueryIterator qIter = exec(base, input);
    for (Expr expr : exprs) qIter = new QueryIterFilterExpr(qIter, expr, execCxt);
    return qIter;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) Expr(org.apache.jena.sparql.expr.Expr) ExprList(org.apache.jena.sparql.expr.ExprList) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Aggregations

ExprList (org.apache.jena.sparql.expr.ExprList)27 Op (org.apache.jena.sparql.algebra.Op)17 Expr (org.apache.jena.sparql.expr.Expr)15 Var (org.apache.jena.sparql.core.Var)11 Node (org.apache.jena.graph.Node)3 Triple (org.apache.jena.graph.Triple)3 HashSet (java.util.HashSet)2 OpFilter (org.apache.jena.sparql.algebra.op.OpFilter)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 Test (org.junit.Test)2 ExprRewriter (org.apache.jena.arq.querybuilder.rewriters.ExprRewriter)1 MockSecurityEvaluator (org.apache.jena.permissions.MockSecurityEvaluator)1 SecurityEvaluator (org.apache.jena.permissions.SecurityEvaluator)1 OpRewriter (org.apache.jena.permissions.query.rewriter.OpRewriter)1 SecuredFunction (org.apache.jena.permissions.query.rewriter.SecuredFunction)1 SortCondition (org.apache.jena.query.SortCondition)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1 VarExprList (org.apache.jena.sparql.core.VarExprList)1 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)1 NodeValue (org.apache.jena.sparql.expr.NodeValue)1