Search in sources :

Example 6 with ReorderTransformation

use of org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation in project jena by apache.

the class StageGeneratorGeneric method execute.

@Override
public QueryIterator execute(BasicPattern pattern, QueryIterator input, ExecutionContext execCxt) {
    if (input == null)
        Log.error(this, "Null input to " + Lib.classShortName(this.getClass()));
    Graph graph = execCxt.getActiveGraph();
    // Choose reorder transformation and execution strategy.
    ReorderTransformation reorder = reorderFixed;
    StageGenerator executor = StageBuilder.executeInline;
    return execute(pattern, reorder, executor, input, execCxt);
}
Also used : Graph(org.apache.jena.graph.Graph) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Example 7 with ReorderTransformation

use of org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation in project jena by apache.

the class tdbreorder method main.

public static void main(String... args) {
    if (args.length != 2) {
        System.err.println("Usage: PATTERN STATS");
        System.exit(1);
    }
    LogCtl.enable(StatsMatcher.class);
    LogCtl.enable(ReorderTransformationSubstitution.class);
    if (args.length != 2) {
        System.err.println("Usage: op stats");
        System.exit(1);
    }
    String pattern = args[0];
    String statsFile = args[1];
    Op op = SSE.readOp(pattern);
    BasicPattern bgp;
    if (op instanceof OpQuadPattern) {
        bgp = ((OpQuadPattern) op).getBasicPattern();
    } else if (op instanceof OpBGP) {
        bgp = ((OpBGP) op).getPattern();
    } else {
        System.err.println("Not a quad or triple pattern");
        System.exit(2);
        bgp = null;
    }
    ReorderTransformation reorder = chooseReorder(statsFile);
    // ReorderTransformation reorder = ReorderLib.fixed() ;
    BasicPattern bgp2 = reorder.reorder(bgp);
    System.out.println();
    print(bgp);
    System.out.println();
    System.out.println(" ======== >>>>>>>>");
    print(bgp2);
    System.out.println();
}
Also used : Op(org.apache.jena.sparql.algebra.Op) OpQuadPattern(org.apache.jena.sparql.algebra.op.OpQuadPattern) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 8 with ReorderTransformation

use of org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation in project jena by apache.

the class OpExecutorTDB2 method optimizeExecuteQuads.

/**
 * Execute, with optimization, a quad pattern
 */
private static QueryIterator optimizeExecuteQuads(DatasetGraphTDB dsgtdb, 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(dsgtdb, input, bgp, exprs, execCxt);
    // ---- Execute quads+filters
    if (bgp.size() >= 2) {
        ReorderTransformation transform = dsgtdb.getReorderTransform();
        if (transform != null) {
            QueryIterPeek peek = QueryIterPeek.create(input, execCxt);
            // Original input now invalid.
            input = peek;
            bgp = reorder(bgp, peek, transform);
        }
    }
    if (exprs == null) {
        // Triple-backed (but may be named as explicit default graph).
        Explain.explain("Execute", bgp, execCxt.getContext());
        Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
        return PatternMatchTDB2.execute(dsgtdb, gn, bgp, input, filter, execCxt);
    }
    // -- Filter placement
    Op op = TransformFilterPlacement.transform(exprs, 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) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 9 with ReorderTransformation

use of org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation in project jena by apache.

the class OpExecutorTDB2 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);
        }
    }
    if (exprs == null) {
        Explain.explain("Execute", pattern, execCxt.getContext());
        Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
        return PatternMatchTDB2.execute(dsgtdb, Quad.defaultGraphNodeGenerated, pattern, input, filter, execCxt);
    }
    // -- Filter placement
    Op op = TransformFilterPlacement.transform(exprs, 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) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 10 with ReorderTransformation

use of org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation 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);
        }
    }
    if (exprs == null) {
        Explain.explain("Execute", pattern, execCxt.getContext());
        Predicate<Tuple<NodeId>> filter = QC2.getFilter(execCxt.getContext());
        return PatternMatchTDB1.execute(dsgtdb, Quad.defaultGraphNodeGenerated, pattern, input, filter, execCxt);
    }
    // -- Filter placement
    Op op = TransformFilterPlacement.transform(exprs, 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) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Aggregations

ReorderTransformation (org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)10 Op (org.apache.jena.sparql.algebra.Op)5 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)4 QueryIterPeek (org.apache.jena.sparql.engine.iterator.QueryIterPeek)4 SSE_ParseException (org.apache.jena.sparql.sse.SSE_ParseException)2 StoragePrefixes (org.apache.jena.dboe.storage.StoragePrefixes)1 Graph (org.apache.jena.graph.Graph)1 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)1 OpQuadPattern (org.apache.jena.sparql.algebra.op.OpQuadPattern)1 BasicPattern (org.apache.jena.sparql.core.BasicPattern)1 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)1 StoreParams (org.apache.jena.tdb2.params.StoreParams)1 ComponentIdMgr (org.apache.jena.tdb2.sys.ComponentIdMgr)1