Search in sources :

Example 1 with ReorderTransformation

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

the class OpExecutorTDB1 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 PatternMatchTDB1.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 2 with ReorderTransformation

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

the class DatasetBuilderStd method buildWorker.

private synchronized DatasetGraphTDB buildWorker(Location location, boolean writeable, ReorderTransformation _transform, StoreParams params) {
    recorder.start();
    DatasetControl policy = createConcurrencyPolicy();
    NodeTable nodeTable = makeNodeTable(location, params);
    TripleTable tripleTable = makeTripleTable(location, nodeTable, policy, params);
    QuadTable quadTable = makeQuadTable(location, nodeTable, policy, params);
    DatasetPrefixesTDB prefixes = makePrefixTable(location, policy, params);
    ReorderTransformation transform = (_transform == null) ? chooseReorderTransformation(location) : _transform;
    StorageConfig storageConfig = new StorageConfig(location, params, writeable, recorder.blockMgrs, recorder.objectFiles, recorder.bufferChannels);
    recorder.finish();
    DatasetGraphTDB dsg = new DatasetGraphTDB(tripleTable, quadTable, prefixes, transform, storageConfig);
    // TDB does filter placement on BGPs itself.
    dsg.getContext().set(ARQ.optFilterPlacementBGP, false);
    QC.setFactory(dsg.getContext(), OpExecutorTDB1.OpExecFactoryTDB);
    return dsg;
}
Also used : ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 3 with ReorderTransformation

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

the class DatasetBuilderStd method chooseOptimizer.

public static ReorderTransformation chooseOptimizer(Location location) {
    if (location == null)
        return ReorderLib.identity();
    ReorderTransformation reorder = null;
    if (location.exists(Names.optStats)) {
        try {
            reorder = ReorderLib.weighted(location.getPath(Names.optStats));
        } catch (SSE_ParseException ex) {
            log.warn("Error in stats file: " + ex.getMessage());
            reorder = null;
        }
    }
    if (reorder == null && location.exists(Names.optFixed)) {
        // Not as good but better than nothing.
        reorder = ReorderLib.fixed();
        log.debug("Fixed pattern BGP optimizer");
    }
    if (location.exists(Names.optNone)) {
        reorder = ReorderLib.identity();
        log.debug("Optimizer explicitly turned off");
    }
    if (reorder == null)
        reorder = SystemTDB.defaultReorderTransform;
    if (reorder == null && warnAboutOptimizer)
        ARQ.getExecLogger().warn("No BGP optimizer");
    return reorder;
}
Also used : SSE_ParseException(org.apache.jena.sparql.sse.SSE_ParseException) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Example 4 with ReorderTransformation

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

the class TDB2StorageBuilder method chooseReorderTransformation.

public static ReorderTransformation chooseReorderTransformation(Location location) {
    if (location == null)
        return ReorderLib.identity();
    ReorderTransformation reorder = null;
    if (location.exists(Names.optStats)) {
        try {
            reorder = ReorderLib.weighted(location.getPath(Names.optStats));
            log.debug("Statistics-based BGP optimizer");
        } catch (SSE_ParseException ex) {
            log.warn("Error in stats file: " + ex.getMessage());
            reorder = null;
        }
    }
    if (reorder == null && location.exists(Names.optFixed)) {
        reorder = ReorderLib.fixed();
        log.debug("Fixed pattern BGP optimizer");
    }
    if (location.exists(Names.optNone)) {
        reorder = ReorderLib.identity();
        log.debug("Optimizer explicitly turned off");
    }
    if (reorder == null)
        reorder = SystemTDB.getDefaultReorderTransform();
    if (reorder == null && warnAboutOptimizer)
        ARQ.getExecLogger().warn("No BGP optimizer");
    return reorder;
}
Also used : SSE_ParseException(org.apache.jena.sparql.sse.SSE_ParseException) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation)

Example 5 with ReorderTransformation

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

the class TDB2StorageBuilder method build.

// public static DatasetGraphTxn build(Location location, StoreParams appParams) {
// StoreParams locParams = StoreParamsCodec.read(location);
// StoreParams dftParams = StoreParams.getDftStoreParams();
// boolean newArea = isNewDatabaseArea(location);
// if ( newArea ) {
// }
// // This can write the chosen parameters if necessary (new database, appParams != null, locParams == null)
// StoreParams params = StoreParamsFactory.decideStoreParams(location, newArea, appParams, locParams, dftParams);
// return create(location, params).build$();
// }
public static DatasetGraphTDB build(Location location, StoreParams appParams) {
    StoreParams locParams = StoreParamsCodec.read(location);
    StoreParams dftParams = StoreParams.getDftStoreParams();
    boolean newArea = isNewDatabaseArea(location);
    if (newArea) {
    }
    // This can write the chosen parameters if necessary (new database, appParams != null, locParams == null)
    StoreParams params = StoreParamsFactory.decideStoreParams(location, newArea, appParams, locParams, dftParams);
    // Builder pattern for adding components.
    TransactionCoordinator txnCoord = buildTransactionCoordinator(location);
    TransactionalSystem txnSystem = new TransactionalBase(txnCoord);
    TDB2StorageBuilder builder = new TDB2StorageBuilder(txnSystem, location, params, new ComponentIdMgr(UUID.randomUUID()));
    StorageTDB storage = builder.buildStorage();
    StoragePrefixes prefixes = builder.buildPrefixes();
    // Finalize.
    builder.components.forEach(txnCoord::add);
    builder.listeners.forEach(txnCoord::addListener);
    // Freezes the TransactionCoordinator components
    txnCoord.start();
    ReorderTransformation reorderTranform = chooseReorderTransformation(location);
    DatasetGraphTDB dsg = new DatasetGraphTDB(location, params, reorderTranform, storage, prefixes, txnSystem);
    // Enable query processing.
    QC.setFactory(dsg.getContext(), OpExecutorTDB2.OpExecFactoryTDB);
    return dsg;
}
Also used : StoreParams(org.apache.jena.tdb2.params.StoreParams) ReorderTransformation(org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation) StoragePrefixes(org.apache.jena.dboe.storage.StoragePrefixes) ComponentIdMgr(org.apache.jena.tdb2.sys.ComponentIdMgr)

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