Search in sources :

Example 16 with TupleMap

use of org.apache.jena.atlas.lib.tuple.TupleMap in project jena by apache.

the class TestTupleMap method map_tuple_3.

@Test
public void map_tuple_3() {
    TupleMap tmap = TupleMap.create("GSPO", "OSPG");
    Tuple<String> tuple = TupleFactory.tuple("G", "S", "P", "O");
    Tuple<String> mapped = tmap.map(tuple);
    Tuple<String> expected = TupleFactory.tuple("O", "S", "P", "G");
    assertEquals(expected, mapped);
    Tuple<String> unmapped = tmap.unmap(mapped);
    assertEquals(TupleFactory.tuple("G", "S", "P", "O"), unmapped);
}
Also used : TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) Test(org.junit.Test)

Example 17 with TupleMap

use of org.apache.jena.atlas.lib.tuple.TupleMap in project jena by apache.

the class TestTupleMap method map_array_1.

@Test
public void map_array_1() {
    TupleMap x = TupleMap.create("SPO", "POS");
    String[] array = { "X", "Y", "Z" };
    // The 0th item after mapping is the "1"
    assertEquals("Y", x.mapSlot(0, array));
    assertEquals("Z", x.mapSlot(1, array));
    assertEquals("X", x.mapSlot(2, array));
    String[] array2 = new String[array.length];
    x.map(array, array2);
    assertArrayEquals(new String[] { "Y", "Z", "X" }, array2);
    String[] array3 = new String[array.length];
    x.unmap(array2, array3);
    assertArrayEquals(array, array3);
}
Also used : TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) Test(org.junit.Test)

Example 18 with TupleMap

use of org.apache.jena.atlas.lib.tuple.TupleMap in project jena by apache.

the class TestTupleMap method compile_1.

@Test
public void compile_1() {
    TupleMap map = TupleMap.create("SPO", "POS");
    // SPO -> POS 
    // col 0 goes to col 2
    // col 1 goes to col 0
    // col 2 goes to col 1
    Integer[] expectedPut = { 2, 0, 1 };
    assertEquals(Arrays.asList(expectedPut), map.transformPut());
    Integer[] expectedGet = { 1, 2, 0 };
    assertEquals(Arrays.asList(expectedGet), map.transformGet());
}
Also used : TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) Test(org.junit.Test)

Example 19 with TupleMap

use of org.apache.jena.atlas.lib.tuple.TupleMap in project jena by apache.

the class TestTupleIndexRecordDirect method create.

static TupleIndexRecord create(String description) {
    IndexParams indexParams = StoreParams.getDftStoreParams();
    RangeIndex rIdx = BuildTestLib.buildRangeIndex(FileSet.mem(), factory, indexParams);
    TupleMap tmap = TupleMap.create("SPO", description);
    TupleIndexRecord index = new TupleIndexRecord(3, tmap, description, factory, rIdx);
    return index;
}
Also used : IndexParams(org.apache.jena.dboe.index.IndexParams) RangeIndex(org.apache.jena.dboe.index.RangeIndex) TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap)

Example 20 with TupleMap

use of org.apache.jena.atlas.lib.tuple.TupleMap in project jena by apache.

the class ProcBuildIndexX method indexBuilder.

private static long indexBuilder(DatasetGraph dsg, InputStream input, String indexName) {
    long tickPoint = BulkLoaderX.DataTick;
    int superTick = BulkLoaderX.DataSuperTick;
    // Location of storage, not the DB.
    DatasetGraphTDB dsgtdb = TDBInternal.getDatasetGraphTDB(dsg);
    Location location = dsgtdb.getLocation();
    int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
    int valueLength = 0;
    // The name is the order.
    String primary = indexName;
    String primaryOrder;
    int dftKeyLength;
    int dftValueLength;
    int tupleLength = indexName.length();
    TupleIndex index;
    if (tupleLength == 3) {
        primaryOrder = Names.primaryIndexTriples;
        dftKeyLength = SystemTDB.LenIndexTripleRecord;
        dftValueLength = 0;
        // Find index.
        index = findIndex(dsgtdb.getTripleTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else if (tupleLength == 4) {
        primaryOrder = Names.primaryIndexQuads;
        dftKeyLength = SystemTDB.LenIndexQuadRecord;
        dftValueLength = 0;
        index = findIndex(dsgtdb.getQuadTable().getNodeTupleTable().getTupleTable().getIndexes(), indexName);
    } else {
        throw new TDBException("Index name: " + indexName);
    }
    TupleMap colMap = TupleMap.create(primaryOrder, indexName);
    int readCacheSize = 10;
    int writeCacheSize = 100;
    int blockSize = SystemTDB.BlockSize;
    RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
    int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
    BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
    int blockSizeNodes = blockSize;
    int blockSizeRecords = blockSize;
    FileSet destination = new FileSet(location, indexName);
    BufferChannel blkState = FileFactory.createBufferChannel(destination, Names.extBptState);
    BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.extBptTree, blockSizeNodes, readCacheSize, writeCacheSize);
    BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.extBptRecords, blockSizeRecords, readCacheSize, writeCacheSize);
    int rowBlock = 1000;
    Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
    // ProgressMonitor.
    ProgressMonitor monitor = ProgressMonitorOutput.create(BulkLoaderX.LOG_Index, indexName, tickPoint, superTick);
    ProgressIterator<Record> iter2 = new ProgressIterator<>(iter, monitor);
    monitor.start();
    BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter2, bptParams, recordFactory, blkState, blkMgrNodes, blkMgrRecords);
    bpt2.close();
    monitor.finish();
    // [BULK] End stage.
    long count = monitor.getTicks();
    return count;
}
Also used : BPlusTreeParams(org.apache.jena.dboe.trans.bplustree.BPlusTreeParams) FileSet(org.apache.jena.dboe.base.file.FileSet) TDBException(org.apache.jena.tdb2.TDBException) BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) DatasetGraphTDB(org.apache.jena.tdb2.store.DatasetGraphTDB) TupleMap(org.apache.jena.atlas.lib.tuple.TupleMap) ProgressIterator(org.apache.jena.system.progress.ProgressIterator) ProgressMonitor(org.apache.jena.system.progress.ProgressMonitor) RecordFactory(org.apache.jena.dboe.base.record.RecordFactory) BlockMgr(org.apache.jena.dboe.base.block.BlockMgr) Record(org.apache.jena.dboe.base.record.Record) TupleIndex(org.apache.jena.tdb2.store.tupletable.TupleIndex) BPlusTree(org.apache.jena.dboe.trans.bplustree.BPlusTree) Location(org.apache.jena.dboe.base.file.Location)

Aggregations

TupleMap (org.apache.jena.atlas.lib.tuple.TupleMap)20 Test (org.junit.Test)16 RangeIndex (org.apache.jena.dboe.index.RangeIndex)3 RecordFactory (org.apache.jena.dboe.base.record.RecordFactory)2 IndexParams (org.apache.jena.dboe.index.IndexParams)2 TupleIndex (org.apache.jena.tdb2.store.tupletable.TupleIndex)2 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 BPlusTree (org.apache.jena.dboe.trans.bplustree.BPlusTree)1 BPlusTreeParams (org.apache.jena.dboe.trans.bplustree.BPlusTreeParams)1 ProgressIterator (org.apache.jena.system.progress.ProgressIterator)1 ProgressMonitor (org.apache.jena.system.progress.ProgressMonitor)1 TDBException (org.apache.jena.tdb2.TDBException)1 DatasetGraphTDB (org.apache.jena.tdb2.store.DatasetGraphTDB)1 TupleIndexRecord (org.apache.jena.tdb2.store.tupletable.TupleIndexRecord)1