Search in sources :

Example 66 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class TransformSliceProject method transform.

@Override
public Op transform(OpSlice opSlice, Op subOp) {
    // (slice (project...)) ==> (project (slice ...))
    if (subOp instanceof OpProject) {
        OpProject p = (OpProject) subOp;
        Op sub = p.getSubOp();
        Op x = new OpSlice(sub, opSlice.getStart(), opSlice.getLength());
        x = new OpProject(x, p.getVars());
        return x;
    }
    return super.transform(opSlice, subOp);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpProject(org.apache.jena.sparql.algebra.op.OpProject) OpSlice(org.apache.jena.sparql.algebra.op.OpSlice)

Example 67 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class QueryIterOpSQL method nextStage.

@Override
protected QueryIterator nextStage(Binding binding) {
    OpSQL execSQL = this.opSQL;
    if (binding != null && !isRoot(binding)) {
        QueryCompiler qc = opSQL.getRequest().getStore().getQueryCompilerFactory().createQueryCompiler(request);
        Op op2 = Substitute.substitute(opSQL.getOriginal(), binding);
        Op op = qc.compile(op2);
        if (op instanceof OpSQL)
            execSQL = (OpSQL) op;
        else
            throw new SDBInternalError("Failed to recompile the OpSQL to an OpSQL");
    }
    return execSQL.exec(binding, getExecContext());
//        QueryIterator qIter = execSQL.exec(binding, getExecContext()) ;
//        List<Binding> x = Iter.toList(qIter) ;
//        qIter = new QueryIterPlainWrapper(x.iterator(), getExecContext()) ;
//        System.out.println("SQL Eval:") ;
//        x.forEach(b -> System.out.println("  "+b) );
//        System.out.println() ;
//        return qIter ;
}
Also used : Op(org.apache.jena.sparql.algebra.Op) SDBInternalError(org.apache.jena.sdb.shared.SDBInternalError)

Example 68 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class AlgebraEx method main.

public static void main(String[] args) {
    String s = "SELECT DISTINCT ?s { ?s ?p ?o }";
    // Parse
    Query query = QueryFactory.create(s);
    System.out.println(query);
    // Generate algebra
    Op op = Algebra.compile(query);
    op = Algebra.optimize(op);
    System.out.println(op);
    // Execute it.
    QueryIterator qIter = Algebra.exec(op, ExQuerySelect1.createModel());
    // Results
    for (; qIter.hasNext(); ) {
        Binding b = qIter.nextBinding();
        System.out.println(b);
    }
    qIter.close();
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Op(org.apache.jena.sparql.algebra.Op) Query(org.apache.jena.query.Query) QueryIterator(org.apache.jena.sparql.engine.QueryIterator)

Example 69 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class TransformExtendCombine method transform.

@Override
public Op transform(OpAssign opAssign, Op subOp) {
    if (subOp instanceof OpAssign) {
        // If a variable is assigned twice, don't do anything.
        // (assign (?x 2)  (assign (?x 1) op)) => leave alone.
        // This is the safest option in a rare case.
        // It would be OK if addAll does a replacement without checking
        // but having it check and complain about duplicates adds robustness.
        // In OpExtend, it's actually illegal.
        OpAssign x = (OpAssign) subOp;
        VarExprList outerVarExprList = opAssign.getVarExprList();
        // Copy
        VarExprList innerVarExprList = new VarExprList(x.getVarExprList());
        Op r = OpAssign.assign(x.getSubOp(), innerVarExprList);
        // This contains an "if already (assign)" test.
        r = OpAssign.assign(r, outerVarExprList);
        return r;
    }
    return super.transform(opAssign, subOp);
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpAssign(org.apache.jena.sparql.algebra.op.OpAssign) VarExprList(org.apache.jena.sparql.core.VarExprList)

Example 70 with Op

use of org.apache.jena.sparql.algebra.Op in project jena by apache.

the class OpN method equalsSubOps.

// Tests the sub-elements for equalTo.
protected boolean equalsSubOps(OpN op, NodeIsomorphismMap labelMap) {
    if (elements.size() != op.elements.size())
        return false;
    Iterator<Op> iter1 = elements.listIterator();
    Iterator<Op> iter2 = op.elements.listIterator();
    for (; iter1.hasNext(); ) {
        Op op1 = iter1.next();
        Op op2 = iter2.next();
        if (!op1.equalTo(op2, labelMap))
            return false;
    }
    return true;
}
Also used : Op(org.apache.jena.sparql.algebra.Op)

Aggregations

Op (org.apache.jena.sparql.algebra.Op)166 Var (org.apache.jena.sparql.core.Var)29 VarExprList (org.apache.jena.sparql.core.VarExprList)18 Query (org.apache.jena.query.Query)17 ExprList (org.apache.jena.sparql.expr.ExprList)17 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)15 Test (org.junit.Test)14 Triple (org.apache.jena.graph.Triple)13 Expr (org.apache.jena.sparql.expr.Expr)13 BasicPattern (org.apache.jena.sparql.core.BasicPattern)11 ArrayList (java.util.ArrayList)9 Node (org.apache.jena.graph.Node)8 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)7 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)7 Binding (org.apache.jena.sparql.engine.binding.Binding)5 ExprVar (org.apache.jena.sparql.expr.ExprVar)5 BaseTest (org.apache.jena.atlas.junit.BaseTest)3 Pair (org.apache.jena.atlas.lib.Pair)3 Table (org.apache.jena.sparql.algebra.Table)3 TransformCopy (org.apache.jena.sparql.algebra.TransformCopy)3