Search in sources :

Example 1 with QueryIterPeek

use of org.apache.jena.sparql.engine.iterator.QueryIterPeek in project jena by apache.

the class OpExecutorTDB1 method optimizeExecuteQuads.

/** Execute, with optimization, a quad pattern */
private static QueryIterator optimizeExecuteQuads(DatasetGraphTDB ds, QueryIterator input, Node gn, BasicPattern bgp, ExprList exprs, ExecutionContext execCxt) {
    if (!input.hasNext())
        return input;
    // ---- Graph names with special meaning. 
    gn = decideGraphNode(gn, execCxt);
    if (gn == null)
        return optimizeExecuteTriples(ds, input, bgp, exprs, execCxt);
    // ---- Execute quads+filters
    if (bgp.size() >= 2) {
        ReorderTransformation transform = ds.getReorderTransform();
        if (transform != null) {
            QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
            // Original input now invalid.
            input = peek;
            bgp = reorder(bgp, peek, transform);
        }
    }
    // -- Filter placement
    Op op = null;
    if (exprs != null)
        op = TransformFilterPlacement.transform(exprs, gn, bgp);
    else
        op = new OpQuadPattern(gn, bgp);
    return plainExecute(op, input, execCxt);
}
Also used : QueryIterPeek(org.apache.jena.sparql.engine.iterator.QueryIterPeek) Op(org.apache.jena.sparql.algebra.Op) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Example 2 with QueryIterPeek

use of org.apache.jena.sparql.engine.iterator.QueryIterPeek in project jena by apache.

the class StageGeneratorGeneric method execute.

protected QueryIterator execute(BasicPattern pattern, ReorderTransformation reorder, StageGenerator execution, QueryIterator input, ExecutionContext execCxt) {
    Explain.explain(pattern, execCxt.getContext());
    if (!input.hasNext())
        return input;
    if (reorder != null && pattern.size() >= 2) {
        // If pattern size is 0 or 1, nothing to do.
        BasicPattern bgp2 = pattern;
        // Try to ground the pattern
        if (!input.isJoinIdentity()) {
            QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
            // And now use this one
            input = peek;
            Binding b = peek.peek();
            bgp2 = Substitute.substitute(pattern, b);
            ReorderProc reorderProc = reorder.reorderIndexes(bgp2);
            pattern = reorderProc.reorder(pattern);
        }
    }
    Explain.explain("Reorder/generic", pattern, execCxt.getContext());
    return QueryIterBlockTriples.create(input, pattern, execCxt);
}
Also used : QueryIterPeek(org.apache.jena.sparql.engine.iterator.QueryIterPeek) Binding(org.apache.jena.sparql.engine.binding.Binding) ReorderProc(org.apache.jena.sparql.engine.optimizer.reorder.ReorderProc) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 3 with QueryIterPeek

use of org.apache.jena.sparql.engine.iterator.QueryIterPeek in project jena by apache.

the class OpExecutorTDB1 method optimizeExecuteTriples.

/** Execute, with optimization, a basic graph pattern on the default graph storage */
private static QueryIterator optimizeExecuteTriples(DatasetGraphTDB dsgtdb, QueryIterator input, BasicPattern pattern, ExprList exprs, ExecutionContext execCxt) {
    if (!input.hasNext())
        return input;
    // Must pass this iterator into the next stage.
    if (pattern.size() >= 2) {
        // Must be 2 or triples to reorder. 
        ReorderTransformation transform = dsgtdb.getReorderTransform();
        if (transform != null) {
            QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
            // Must pass on
            input = peek;
            pattern = reorder(pattern, peek, transform);
        }
    }
    // -- Filter placement
    Op op = null;
    if (exprs != null)
        op = TransformFilterPlacement.transform(exprs, pattern);
    else
        op = new OpBGP(pattern);
    return plainExecute(op, input, execCxt);
}
Also used : QueryIterPeek(org.apache.jena.sparql.engine.iterator.QueryIterPeek) Op(org.apache.jena.sparql.algebra.Op) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Aggregations

QueryIterPeek (org.apache.jena.sparql.engine.iterator.QueryIterPeek)3 Op (org.apache.jena.sparql.algebra.Op)2 ReorderTransformation (org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 Binding (org.apache.jena.sparql.engine.binding.Binding)1 ReorderProc (org.apache.jena.sparql.engine.optimizer.reorder.ReorderProc)1