Search in sources :

Example 16 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class SolverRX method find.

private static Iterator<BindingNodeId> find(BindingNodeId bnid, NodeTupleTable nodeTupleTable, Node xGraphNode, Triple xPattern, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Binding input = bnid.isEmpty() ? BindingFactory.empty() : new BindingTDB(bnid, nodeTable);
    Triple tPattern = Substitute.substitute(xPattern, input);
    Node graphNode = Substitute.substitute(xGraphNode, input);
    Node tGraphNode = anyGraph ? Quad.unionGraph : graphNode;
    // graphNode is ANY for union graph and null for default graph.
    // Var to ANY, Triple Term to ANY.
    Node g = (graphNode == null) ? null : nodeTopLevel(graphNode);
    Node s = nodeTopLevel(tPattern.getSubject());
    Node p = nodeTopLevel(tPattern.getPredicate());
    Node o = nodeTopLevel(tPattern.getObject());
    Tuple<Node> patternTuple = (g == null) ? TupleFactory.create3(s, p, o) : TupleFactory.create4(g, s, p, o);
    Iterator<Quad> dsgIter = accessData(patternTuple, nodeTupleTable, anyGraph, filter, execCxt);
    Iterator<Binding> matched = Iter.iter(dsgIter).map(dQuad -> SolverRX4.matchQuad(input, dQuad, tGraphNode, tPattern)).removeNulls();
    return convFromBinding(matched, nodeTable);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) SolverLibTDB.convFromBinding(org.apache.jena.tdb2.solver.SolverLibTDB.convFromBinding) Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) NodeId(org.apache.jena.tdb2.store.NodeId) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) Function(java.util.function.Function) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) SolverRX4(org.apache.jena.sparql.engine.main.solver.SolverRX4) Substitute(org.apache.jena.sparql.core.Substitute) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) TupleLib(org.apache.jena.tdb2.lib.TupleLib) TupleFactory(org.apache.jena.atlas.lib.tuple.TupleFactory) SolverLibTDB.convFromBinding(org.apache.jena.tdb2.solver.SolverLibTDB.convFromBinding) Iter(org.apache.jena.atlas.iterator.Iter) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) BindingFactory(org.apache.jena.sparql.engine.binding.BindingFactory) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 17 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class OpExecutorTDB2 method plainExecute.

/**
 * Execute without modification of the op - does <b>not</b> apply special graph name translations
 */
private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt) {
    // -- Execute
    // Switch to a non-reordering executor
    // The Op may be a sequence due to TransformFilterPlacement
    // so we need to do a full execution step, not go straight to the SolverLib.
    ExecutionContext ec2 = new ExecutionContext(execCxt);
    ec2.setExecutor(plainFactory);
    // so there are no nested patterns to reorder.
    return QC.execute(op, input, ec2);
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext)

Example 18 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class SpatialIndex method retrieve.

/**
 * Retrieve the SpatialIndex from the Context.
 *
 * @param execCxt
 * @return SpatialIndex contained in the Context.
 * @throws SpatialIndexException
 */
public static final SpatialIndex retrieve(ExecutionContext execCxt) throws SpatialIndexException {
    Context context = execCxt.getContext();
    SpatialIndex spatialIndex = (SpatialIndex) context.get(SPATIAL_INDEX_SYMBOL, null);
    if (spatialIndex == null) {
        throw new SpatialIndexException("Dataset Context does not contain SpatialIndex.");
    }
    return spatialIndex;
}
Also used : Context(org.apache.jena.sparql.util.Context) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext)

Example 19 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class SolverRX method find.

private static Iterator<BindingNodeId> find(BindingNodeId bnid, NodeTupleTable nodeTupleTable, Node xGraphNode, Triple xPattern, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Binding input = bnid.isEmpty() ? BindingFactory.empty() : new BindingTDB(bnid, nodeTable);
    Triple tPattern = Substitute.substitute(xPattern, input);
    Node graphNode = Substitute.substitute(xGraphNode, input);
    Node tGraphNode = anyGraph ? Quad.unionGraph : graphNode;
    // graphNode is ANY for union graph and null for default graph.
    // Var to ANY, Triple Term to ANY.
    Node g = (graphNode == null) ? null : nodeTopLevel(graphNode);
    Node s = nodeTopLevel(tPattern.getSubject());
    Node p = nodeTopLevel(tPattern.getPredicate());
    Node o = nodeTopLevel(tPattern.getObject());
    Tuple<Node> patternTuple = (g == null) ? TupleFactory.create3(s, p, o) : TupleFactory.create4(g, s, p, o);
    Iterator<Quad> dsgIter = accessData(patternTuple, nodeTupleTable, anyGraph, filter, execCxt);
    Iterator<Binding> matched = Iter.iter(dsgIter).map(dQuad -> SolverRX4.matchQuad(input, dQuad, tGraphNode, tPattern)).removeNulls();
    return convFromBinding(matched, nodeTable);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) SolverLibTDB.convFromBinding(org.apache.jena.tdb.solver.SolverLibTDB.convFromBinding) Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) Iterator(java.util.Iterator) Predicate(java.util.function.Predicate) TupleLib(org.apache.jena.tdb.lib.TupleLib) SolverLib.nodeTopLevel(org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel) Triple(org.apache.jena.graph.Triple) SolverLibTDB.convFromBinding(org.apache.jena.tdb.solver.SolverLibTDB.convFromBinding) SolverLib.tripleHasEmbTripleWithVars(org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars) Function(java.util.function.Function) NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb.store.NodeId) SolverRX4(org.apache.jena.sparql.engine.main.solver.SolverRX4) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Substitute(org.apache.jena.sparql.core.Substitute) Node(org.apache.jena.graph.Node) Quad(org.apache.jena.sparql.core.Quad) TupleFactory(org.apache.jena.atlas.lib.tuple.TupleFactory) Iter(org.apache.jena.atlas.iterator.Iter) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) BindingFactory(org.apache.jena.sparql.engine.binding.BindingFactory) Quad(org.apache.jena.sparql.core.Quad) Node(org.apache.jena.graph.Node) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 20 with ExecutionContext

use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.

the class OpExecutorTDB1 method plainExecute.

/**
 * Execute without modification of the op - does <b>not</b> apply special graph name translations
 */
private static QueryIterator plainExecute(Op op, QueryIterator input, ExecutionContext execCxt) {
    // -- Execute
    // Switch to a non-reordering executor
    // The Op may be a sequence due to TransformFilterPlacement
    // so we need to do a full execution step, not go straight to the SolverLib.
    ExecutionContext ec2 = new ExecutionContext(execCxt);
    ec2.setExecutor(plainFactory);
    // so there are no nested patterns to reorder.
    return QC.execute(op, input, ec2);
}
Also used : ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext)

Aggregations

ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)40 Context (org.apache.jena.sparql.util.Context)19 Node (org.apache.jena.graph.Node)14 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)12 Test (org.junit.Test)12 Binding (org.apache.jena.sparql.engine.binding.Binding)11 Triple (org.apache.jena.graph.Triple)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9 Iterator (java.util.Iterator)8 Iter (org.apache.jena.atlas.iterator.Iter)8 Var (org.apache.jena.sparql.core.Var)8 Predicate (java.util.function.Predicate)7 Graph (org.apache.jena.graph.Graph)7 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)6 Function (java.util.function.Function)5 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Quad (org.apache.jena.sparql.core.Quad)5 Substitute (org.apache.jena.sparql.core.Substitute)5 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)5