Search in sources :

Example 1 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class tdbstats method stats$.

private static StatsResults stats$(DatasetGraphTDB dsg, Node gn) {
    NodeTable nt = dsg.getTripleTable().getNodeTupleTable().getNodeTable();
    StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
    if (gn == null) {
        Iterator<Tuple<NodeId>> iter = dsg.getTripleTable().getNodeTupleTable().findAll();
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(null, t.get(0), t.get(1), t.get(2));
        }
    } else {
        // If the union graph, then we need to scan all quads but with uniqueness.
        boolean unionGraph = Quad.isUnionGraph(gn);
        NodeId gnid = null;
        if (!unionGraph) {
            gnid = nt.getNodeIdForNode(gn);
            if (NodeId.isDoesNotExist(gnid))
                Log.warn(tdbstats.class, "No such graph: " + gn);
        }
        NodeTupleTable ntt = dsg.getQuadTable().getNodeTupleTable();
        Iterator<Tuple<NodeId>> iter = unionGraph ? SolverLibTDB.unionGraph(ntt) : ntt.find(gnid, null, null, null);
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(t.get(0), t.get(1), t.get(2), t.get(3));
        }
    }
    return stats.results();
}
Also used : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable) NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Example 2 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable 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 NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class SolverRX method matchQuadPattern.

// Entry point from SolverLib.
/*package*/
static Iterator<BindingNodeId> matchQuadPattern(Iterator<BindingNodeId> chain, Node graphNode, Triple tPattern, NodeTupleTable nodeTupleTable, Tuple<Node> patternTuple, boolean anyGraph, Predicate<Tuple<NodeId>> filter, ExecutionContext execCxt) {
    if (DATAPATH) {
        if (!tripleHasEmbTripleWithVars(tPattern))
            // No RDF-star <<>> with variables.
            return StageMatchTuple.access(nodeTupleTable, chain, patternTuple, filter, anyGraph, execCxt);
    }
    // RDF-star <<>> with variables.
    // This path should work regardless.
    boolean isTriple = (patternTuple.len() == 3);
    NodeTable nodeTable = nodeTupleTable.getNodeTable();
    Function<BindingNodeId, Iterator<BindingNodeId>> step = bnid -> find(bnid, nodeTupleTable, graphNode, tPattern, anyGraph, filter, execCxt);
    return Iter.flatMap(chain, step);
}
Also used : 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) Iterator(java.util.Iterator) NodeTable(org.apache.jena.tdb2.store.nodetable.NodeTable)

Example 4 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable 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 5 with NodeTupleTable

use of org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable in project jena by apache.

the class DataToTuplesInlineSingle method startBulk.

@Override
public void startBulk() {
    coordinator = CoLib.newCoordinator();
    CoLib.add(coordinator, nodeTable);
    // Prefixes
    NodeTupleTable p = prefixes.getNodeTupleTable();
    CoLib.add(coordinator, p.getNodeTable());
    CoLib.add(coordinator, p.getTupleTable().getIndexes());
    CoLib.start(coordinator);
    transaction = coordinator.begin(TxnType.WRITE);
}
Also used : NodeTupleTable(org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)

Aggregations

NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)8 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)6 NodeId (org.apache.jena.tdb2.store.NodeId)5 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)5 Node (org.apache.jena.graph.Node)4 Quad (org.apache.jena.sparql.core.Quad)4 Iterator (java.util.Iterator)3 Iter (org.apache.jena.atlas.iterator.Iter)3 Triple (org.apache.jena.graph.Triple)3 Binding (org.apache.jena.sparql.engine.binding.Binding)3 Function (java.util.function.Function)2 Predicate (java.util.function.Predicate)2 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)2 TupleFactory (org.apache.jena.atlas.lib.tuple.TupleFactory)2 Substitute (org.apache.jena.sparql.core.Substitute)2 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)2 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)2 SolverLib.nodeTopLevel (org.apache.jena.sparql.engine.main.solver.SolverLib.nodeTopLevel)2 SolverLib.tripleHasEmbTripleWithVars (org.apache.jena.sparql.engine.main.solver.SolverLib.tripleHasEmbTripleWithVars)2 SolverRX4 (org.apache.jena.sparql.engine.main.solver.SolverRX4)2