Search in sources :

Example 56 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class TupleTable method find.

/**
 * Find all matching tuples - a slot of NodeId.NodeIdAny means match any
 */
public Iterator<Tuple<NodeId>> find(Tuple<NodeId> pattern) {
    if (tupleLen != pattern.len())
        throw new TDBException(format("Mismatch: finding tuple of length %d in a table of tuples of length %d", pattern.len(), tupleLen));
    int numSlots = 0;
    // Canonical form.
    for (int i = 0; i < tupleLen; i++) {
        NodeId x = pattern.get(i);
        if (!NodeId.isAny(x))
            numSlots++;
        if (NodeId.isDoesNotExist(x))
            return Iter.nullIterator();
    }
    if (numSlots == 0)
        return scanAllIndex.all();
    int indexNumSlots = 0;
    TupleIndex index = null;
    for (TupleIndex idx : indexes) {
        if (idx != null) {
            int w = idx.weight(pattern);
            if (w > indexNumSlots) {
                indexNumSlots = w;
                index = idx;
            }
        }
    }
    if (index == null)
        // No index at all.  Scan.
        index = indexes[0];
    return index.find(pattern);
}
Also used : TDBException(org.apache.jena.tdb2.TDBException) NodeId(org.apache.jena.tdb2.store.NodeId)

Example 57 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class TupleTable method add.

/**
 * Insert a tuple
 */
public void add(Tuple<NodeId> t) {
    // the indexes when the triple is already present.
    if (tupleLen != t.len())
        throw new TDBException(format("Mismatch: inserting tuple of length %d into a table of tuples of length %d", t.len(), tupleLen));
    for (int i = 0; i < indexes.length; i++) {
        if (indexes[i] == null)
            continue;
        indexes[i].add(t);
        syncNeeded = true;
    }
}
Also used : TDBException(org.apache.jena.tdb2.TDBException)

Example 58 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class TestStats method stats_02.

@Test
public void stats_02() {
    NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g1"));
    StatsResults r = statsForGraph(gid);
    assertEquals(1, r.getCount());
    assertEquals(1, r.getPredicates().keySet().size());
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) StatsResults(org.apache.jena.tdb2.solver.stats.StatsResults) Test(org.junit.Test)

Example 59 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class TestStats method statsForDftGraph.

private StatsResults statsForDftGraph() {
    // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
    return Txn.calculateWrite(dsg, () -> {
        Iterator<Tuple<NodeId>> iter = triples.findAll();
        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
        for (; iter.hasNext(); ) {
            Tuple<NodeId> t = iter.next();
            stats.record(null, t.get(0), t.get(1), t.get(2));
        }
        return stats.results();
    });
}
Also used : NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Example 60 with NodeId

use of org.apache.jena.tdb2.store.NodeId in project jena by apache.

the class TestStats method statsForGraph.

private StatsResults statsForGraph(NodeId gid) {
    // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
    return Txn.calculateWrite(dsg, () -> {
        Iterator<Tuple<NodeId>> iter = quads.find(gid, null, null, null);
        StatsCollectorNodeId stats = new StatsCollectorNodeId(nt);
        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 : NodeId(org.apache.jena.tdb2.store.NodeId) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) StatsCollectorNodeId(org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)

Aggregations

NodeId (org.apache.jena.tdb2.store.NodeId)47 Node (org.apache.jena.graph.Node)24 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)16 TDBException (org.apache.jena.tdb2.TDBException)12 NodeTable (org.apache.jena.tdb2.store.nodetable.NodeTable)11 Quad (org.apache.jena.sparql.core.Quad)7 ArrayList (java.util.ArrayList)6 Var (org.apache.jena.sparql.core.Var)6 Triple (org.apache.jena.graph.Triple)5 NodeTupleTable (org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable)5 Iterator (java.util.Iterator)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4 StatsCollectorNodeId (org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId)4 Predicate (java.util.function.Predicate)3 Iter (org.apache.jena.atlas.iterator.Iter)3 Record (org.apache.jena.dboe.base.record.Record)3 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)3 Test (org.junit.Test)3 List (java.util.List)2 Function (java.util.function.Function)2