Search in sources :

Example 16 with TupleIndex

use of org.apache.jena.tdb.store.tupletable.TupleIndex in project jena by apache.

the class tdbgenindex method main.

public static void main(String... argv) {
    // Usage: srcLocation indexName dstLocation indexName
    if (argv.length != 4) {
        System.err.println("Usage: " + Lib.classShortName(tdbgenindex.class) + " srcLocation srcIndex dstLocation dstIndex");
        System.exit(1);
    }
    Location srcLoc = Location.create(argv[0]);
    String srcIndexName = argv[1];
    Location dstLoc = Location.create(argv[2]);
    String dstIndexName = argv[3];
    int readCacheSize = 0;
    int writeCacheSize = -1;
    if (srcIndexName.length() != dstIndexName.length()) {
        System.err.println("srcIndexName.length() != dstIndexName.length() " + srcIndexName + " :: " + dstIndexName);
        System.exit(1);
    }
    String primary;
    int dftKeyLength;
    int dftValueLength;
    if (srcIndexName.length() == 3) {
        primary = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
    } else if (srcIndexName.length() == 4) {
        primary = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
    } else {
        System.err.println("indexlength != 3 or 4");
        System.exit(1);
        primary = null;
        dftKeyLength = 0;
        dftValueLength = 0;
    }
    TupleIndex srcIdx = SetupTDB.makeTupleIndex(srcLoc, primary, srcIndexName, srcIndexName, dftKeyLength);
    TupleIndex dstIdx = SetupTDB.makeTupleIndex(dstLoc, primary, dstIndexName, dstIndexName, dftKeyLength);
    Iterator<Tuple<NodeId>> iter = srcIdx.all();
    for (; iter.hasNext(); ) {
        Tuple<NodeId> tuple = iter.next();
        dstIdx.add(tuple);
    }
    srcIdx.close();
    dstIdx.close();
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) Location(org.apache.jena.tdb.base.file.Location)

Example 17 with TupleIndex

use of org.apache.jena.tdb.store.tupletable.TupleIndex in project jena by apache.

the class BuilderSecondaryIndexesSequential method createSecondaryIndexes.

// Create each secondary indexes, doing one at a time.
@Override
public void createSecondaryIndexes(TupleIndex primaryIndex, TupleIndex[] secondaryIndexes) {
    Timer timer = new Timer();
    timer.startTimer();
    for (TupleIndex index : secondaryIndexes) {
        if (index != null) {
            long time1 = timer.readTimer();
            LoaderNodeTupleTable.copyIndex(primaryIndex.all(), new TupleIndex[] { index }, index.getMapping(), monitor);
            long time2 = timer.readTimer();
        //                if ( printTiming )
        //                    printf("Time for %s indexing: %.2fs\n", index.getLabel(), (time2-time1)/1000.0) ;
        //                if ( printTiming )
        //                    printer.println() ;
        }
    }
}
Also used : Timer(org.apache.jena.atlas.lib.Timer) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex)

Example 18 with TupleIndex

use of org.apache.jena.tdb.store.tupletable.TupleIndex in project jena by apache.

the class DatasetBuilderStd method makePrefixTable.

protected DatasetPrefixesTDB makePrefixTable(Location location, DatasetControl policy, StoreParams params) {
    String primary = params.getPrimaryIndexPrefix();
    String[] indexes = params.getPrefixIndexes();
    TupleIndex[] prefixIndexes = makeTupleIndexes(location, primary, indexes, new String[] { params.getIndexPrefix() }, params);
    if (prefixIndexes.length != 1)
        error(log, "Wrong number of triple table tuples indexes: " + prefixIndexes.length);
    String pnNode2Id = params.getPrefixNode2Id();
    String pnId2Node = params.getPrefixId2Node();
    // No cache - the prefix mapping is a cache
    NodeTable prefixNodes = makeNodeTableNoCache(location, pnNode2Id, pnId2Node, params);
    NodeTupleTable prefixTable = new NodeTupleTableConcrete(primary.length(), prefixIndexes, prefixNodes, policy);
    DatasetPrefixesTDB prefixes = new DatasetPrefixesTDB(prefixTable);
    log.debug("Prefixes: " + primary + " :: " + String.join(",", indexes));
    return prefixes;
}
Also used : NodeTupleTable(org.apache.jena.tdb.store.nodetupletable.NodeTupleTable) NodeTupleTableConcrete(org.apache.jena.tdb.store.nodetupletable.NodeTupleTableConcrete) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable)

Example 19 with TupleIndex

use of org.apache.jena.tdb.store.tupletable.TupleIndex in project jena by apache.

the class AbstractTestTupleIndex method TupleIndexRecordSPO_8.

@Test
public void TupleIndexRecordSPO_8() {
    TupleIndex index = createIndex("SPO");
    add(index, n1, n2, n3);
    add(index, n2, n3, n4);
    {
        Tuple<NodeId> tuple2 = TupleFactory.tuple(n1, NodeId.NodeIdAny, NodeId.NodeIdAny);
        Iterator<Tuple<NodeId>> iter = index.find(tuple2);
        Set<Tuple<NodeId>> x = Iter.toSet(iter);
        assertEquals(1, x.size());
        assertTrue(x.contains(TupleFactory.tuple(n1, n2, n3)));
    }
    {
        Tuple<NodeId> tuple2 = TupleFactory.tuple(n2, NodeId.NodeIdAny, NodeId.NodeIdAny);
        Iterator<Tuple<NodeId>> iter = index.find(tuple2);
        Set<Tuple<NodeId>> x = Iter.toSet(iter);
        assertEquals(1, x.size());
        assertTrue(x.contains(TupleFactory.tuple(n2, n3, n4)));
    }
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 20 with TupleIndex

use of org.apache.jena.tdb.store.tupletable.TupleIndex in project jena by apache.

the class AbstractTestTupleIndex method TupleIndexRecordSPO_4.

@Test
public void TupleIndexRecordSPO_4() {
    TupleIndex index = createIndex("SPO");
    add(index, n1, n2, n3);
    Tuple<NodeId> tuple2 = TupleFactory.tuple(n1, NodeId.NodeIdAny, NodeId.NodeIdAny);
    Iterator<Tuple<NodeId>> iter = index.find(tuple2);
    assertTrue(iter.hasNext());
    iter.next();
    assertFalse(iter.hasNext());
}
Also used : NodeId(org.apache.jena.tdb.store.NodeId) TupleIndex(org.apache.jena.tdb.store.tupletable.TupleIndex) Tuple(org.apache.jena.atlas.lib.tuple.Tuple) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

TupleIndex (org.apache.jena.tdb.store.tupletable.TupleIndex)28 NodeId (org.apache.jena.tdb.store.NodeId)20 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)19 BaseTest (org.apache.jena.atlas.junit.BaseTest)18 Test (org.junit.Test)18 Location (org.apache.jena.tdb.base.file.Location)3 Timer (org.apache.jena.atlas.lib.Timer)2 RangeIndex (org.apache.jena.tdb.index.RangeIndex)2 ColumnMap (org.apache.jena.tdb.lib.ColumnMap)2 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)2 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Semaphore (java.util.concurrent.Semaphore)1 FileSet (org.apache.jena.tdb.base.file.FileSet)1 Record (org.apache.jena.tdb.base.record.Record)1 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)1 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)1 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)1 NodeTupleTable (org.apache.jena.tdb.store.nodetupletable.NodeTupleTable)1 NodeTupleTableConcrete (org.apache.jena.tdb.store.nodetupletable.NodeTupleTableConcrete)1