Search in sources :

Example 1 with QueryIterAbortable

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

the class PatternMatchData method execute.

/**
 * Non-reordering execution of a quad pattern, a graph name and a basic graph pattern,
 *  given an iterator of bindings as input.
 *  <p>
 *  GraphNode is Node.ANY for execution over the union of named graphs.<br/>
 *  GraphNode is null for execution over the real default graph.
 */
public static QueryIterator execute(DatasetGraph dsg, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Quad> filter, ExecutionContext execCxt) {
    // graphNode may be null, meaning default graph
    if (Quad.isUnionGraph(graphNode))
        graphNode = Node.ANY;
    if (Quad.isDefaultGraph(graphNode))
        graphNode = null;
    List<Triple> triples = pattern.getList();
    boolean isDefaultGraph = (graphNode == null);
    boolean anyGraph = isDefaultGraph ? false : (Node.ANY.equals(graphNode));
    Iterator<Binding> chain = input;
    List<Abortable> killList = new ArrayList<>();
    for (Triple triple : triples) {
        // Plain - no RDF-star.
        // chain = StageMatchData.accessQuad(chain, graphNode, triple, filter, anyGraph, execCxt);
        // [Match] Missing filter.
        chain = SolverRX4.rdfStarQuad(chain, graphNode, triple, execCxt);
        chain = SolverLib.makeAbortable(chain, killList);
    }
    // "killList" will be aborted on timeout.
    return new QueryIterAbortable(chain, killList, input, execCxt);
}
Also used : Triple(org.apache.jena.graph.Triple) Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) ArrayList(java.util.ArrayList)

Example 2 with QueryIterAbortable

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

the class PatternMatchTDB2 method execute.

// The worker.  Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (Quad.isUnionGraph(graphNode))
        graphNode = Node.ANY;
    if (Quad.isDefaultGraph(graphNode))
        graphNode = null;
    List<Triple> triples = pattern.getList();
    boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
    int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
    if (graphNode == null) {
        if (3 != tupleLen)
            throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
    } else {
        if (4 != tupleLen)
            throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
    }
    // Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
    List<Abortable> killList = new ArrayList<>();
    for (Triple triple : triples) {
        Tuple<Node> patternTuple = null;
        if (graphNode == null)
            // 3-tuples
            patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
        else
            // 4-tuples.
            patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
        // Plain RDF, no RDF-star
        // chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
        // ;
        // RDF-star SA
        chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
        chain = makeAbortable(chain, killList);
    }
    Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
    // "killList" will be aborted on timeout.
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) TDBException(org.apache.jena.tdb2.TDBException) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Triple(org.apache.jena.graph.Triple) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 3 with QueryIterAbortable

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

the class SolverLibTDB method graphNames.

/**
 * Find all the graph names in the quads table.
 */
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    List<Abortable> killList = new ArrayList<>();
    Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
    if (filter != null)
        iter1 = Iter.filter(iter1, filter);
    Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
    // Project is cheap - don't brother wrapping iter1
    iter2 = makeAbortable(iter2, killList);
    Iterator<NodeId> iter3 = Iter.distinct(iter2);
    iter3 = makeAbortable(iter3, killList);
    Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
    final Var var = Var.alloc(graphNode);
    Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeId(org.apache.jena.tdb2.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Example 4 with QueryIterAbortable

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

the class PatternMatchTDB1 method execute.

// The worker.  Callers choose the NodeTupleTable.
// graphNode may be Node.ANY, meaning we should make triples unique.
// graphNode may be null, meaning default graph
private static QueryIterator execute(NodeTupleTable nodeTupleTable, Node graphNode, BasicPattern pattern, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (Quad.isUnionGraph(graphNode))
        graphNode = Node.ANY;
    if (Quad.isDefaultGraph(graphNode))
        graphNode = null;
    List<Triple> triples = pattern.getList();
    boolean anyGraph = (graphNode == null ? false : (Node.ANY.equals(graphNode)));
    int tupleLen = nodeTupleTable.getTupleTable().getTupleLen();
    if (graphNode == null) {
        if (3 != tupleLen)
            throw new TDBException("SolverLib: Null graph node but tuples are of length " + tupleLen);
    } else {
        if (4 != tupleLen)
            throw new TDBException("SolverLib: Graph node specified but tuples are of length " + tupleLen);
    }
    // Convert from a QueryIterator (Bindings of Var/Node) to BindingNodeId
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Iterator<BindingNodeId> chain = Iter.map(input, SolverLibTDB.convFromBinding(nodeTable));
    List<Abortable> killList = new ArrayList<>();
    for (Triple triple : triples) {
        Tuple<Node> patternTuple = null;
        if (graphNode == null)
            // 3-tuples
            patternTuple = TupleFactory.create3(triple.getSubject(), triple.getPredicate(), triple.getObject());
        else
            // 4-tuples.
            patternTuple = TupleFactory.create4(graphNode, triple.getSubject(), triple.getPredicate(), triple.getObject());
        // Plain RDF, no RDF-star
        // chain = solve(nodeTupleTable, tuple, anyGraph, chain, filter, execCxt)
        // ;
        // RDF-star SA
        chain = matchQuadPattern(chain, graphNode, triple, nodeTupleTable, patternTuple, anyGraph, filter, execCxt);
        chain = makeAbortable(chain, killList);
    }
    Iterator<Binding> iterBinding = SolverLibTDB.convertToNodes(chain, nodeTable);
    // "killList" will be aborted on timeout.
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) TDBException(org.apache.jena.tdb.TDBException) Node(org.apache.jena.graph.Node) ArrayList(java.util.ArrayList) Triple(org.apache.jena.graph.Triple) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 5 with QueryIterAbortable

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

the class SolverLibTDB method graphNames.

/**
 * Find all the graph names in the quads table.
 */
static QueryIterator graphNames(DatasetGraphTDB ds, Node graphNode, QueryIterator input, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    List<Abortable> killList = new ArrayList<>();
    Iterator<Tuple<NodeId>> iter1 = ds.getQuadTable().getNodeTupleTable().find(NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny, NodeId.NodeIdAny);
    if (filter != null)
        iter1 = Iter.filter(iter1, filter);
    Iterator<NodeId> iter2 = Iter.map(iter1, t -> t.get(0));
    // Project is cheap - don't brother wrapping iter1
    iter2 = makeAbortable(iter2, killList);
    Iterator<NodeId> iter3 = Iter.distinct(iter2);
    iter3 = makeAbortable(iter3, killList);
    Iterator<Node> iter4 = NodeLib.nodes(ds.getQuadTable().getNodeTupleTable().getNodeTable(), iter3);
    final Var var = Var.alloc(graphNode);
    Iterator<Binding> iterBinding = Iter.map(iter4, node -> BindingFactory.binding(var, node));
    return new QueryIterAbortable(iterBinding, killList, input, execCxt);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) QueryIterAbortable(org.apache.jena.sparql.engine.iterator.QueryIterAbortable) SolverLib.makeAbortable(org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable) Abortable(org.apache.jena.sparql.engine.iterator.Abortable) NodeId(org.apache.jena.tdb.store.NodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple)

Aggregations

Binding (org.apache.jena.sparql.engine.binding.Binding)6 Abortable (org.apache.jena.sparql.engine.iterator.Abortable)6 QueryIterAbortable (org.apache.jena.sparql.engine.iterator.QueryIterAbortable)6 ArrayList (java.util.ArrayList)4 Node (org.apache.jena.graph.Node)4 Triple (org.apache.jena.graph.Triple)4 SolverLib.makeAbortable (org.apache.jena.sparql.engine.main.solver.SolverLib.makeAbortable)4 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 Var (org.apache.jena.sparql.core.Var)2 TDBException (org.apache.jena.tdb.TDBException)1 NodeId (org.apache.jena.tdb.store.NodeId)1 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)1 TDBException (org.apache.jena.tdb2.TDBException)1 NodeId (org.apache.jena.tdb2.store.NodeId)1 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)1