Search in sources :

Example 11 with TupleIndex

use of org.apache.jena.tdb2.store.tupletable.TupleIndex 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)

Aggregations

TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)8 NodeId (org.apache.jena.tdb2.store.NodeId)4 ProgressMonitor (org.apache.jena.system.progress.ProgressMonitor)3 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)2 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 RangeIndex (org.apache.jena.dboe.index.RangeIndex)2 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)2 TDBException (org.apache.jena.tdb2.TDBException)2 TupleIndexRecord (org.apache.jena.tdb2.store.tupletable.TupleIndexRecord)2 List (java.util.List)1 BlockMgr (org.apache.jena.dboe.base.block.BlockMgr)1 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)1 FileSet (org.apache.jena.dboe.base.file.FileSet)1 Location (org.apache.jena.dboe.base.file.Location)1 Record (org.apache.jena.dboe.base.record.Record)1 BPlusTreeParams (org.apache.jena.dboe.trans.bplustree.BPlusTreeParams)1 ProgressIterator (org.apache.jena.system.progress.ProgressIterator)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1 StoragePrefixesTDB (org.apache.jena.tdb2.store.StoragePrefixesTDB)1