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);
}
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;
}
}
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());
}
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();
});
}
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();
});
}
Aggregations