Search in sources :

Example 21 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPTreeNodeBuilder method next.

@Override
public Pair<Integer, Record> next() {
    if (!hasNext())
        throw new NoSuchElementException();
    Pair<Integer, Record> x = slot;
    slot = null;
    return x;
}
Also used : Record(org.apache.jena.tdb.base.record.Record) NoSuchElementException(java.util.NoSuchElementException)

Example 22 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class BPTreeNodeBuilder method hasNext.

@Override
public boolean hasNext() {
    if (slot != null)
        return true;
    if (iter == null)
        return false;
    if (!iter.hasNext()) {
        // Start of next block, no more input.
        iter = null;
        return false;
    }
    // At least one element to put in a new node.
    // Unknown parent.  Does not matter (parent is only in-memory) 
    BPTreeNode bptNode = mgr.createNode(-1);
    bptNode.setIsLeaf(leafLayer);
    RecordBuffer recBuff = bptNode.getRecordBuffer();
    PtrBuffer ptrBuff = bptNode.getPtrBuffer();
    recBuff.setSize(0);
    // Creation leaves this junk.
    ptrBuff.setSize(0);
    final boolean debug = false;
    int rMax = recBuff.maxSize();
    int pMax = ptrBuff.maxSize();
    if (debug)
        System.out.printf("Max: (%d, %d)\n", rMax, pMax);
    for (; iter.hasNext(); ) {
        int X = bptNode.getCount();
        int X2 = bptNode.getMaxSize();
        int P = ptrBuff.size();
        int P2 = ptrBuff.maxSize();
        int R = recBuff.size();
        int R2 = recBuff.maxSize();
        // bptNode.getMaxSize() is drivel
        //System.out.printf("N: %d/%d : P %d/%d : R %d/%d\n", X, X2, P, P2, R, R2) ;
        Pair<Integer, Record> pair = iter.next();
        if (debug)
            System.out.println("** Item: " + pair);
        Record r = pair.cdr();
        // [Issue: FREC]
        // The record buffer size is wrong.
        // Writes the whole record, only need to write the key part.
        // **** r = recordFactory.createKeyOnly(r) ;
        // [Issue: FREC]
        // The record is key-only (which is correct) but until FREC fixed, we need key,value
        r = recordFactory.create(r.getKey());
        // There is always one more ptr than record in a B+Tree node.
        if (ptrBuff.isFull())
            System.err.println("PtrBuffer is full");
        // Add pointer.
        ptrBuff.add(pair.car());
        // .... test ptrBuff
        if (ptrBuff.isFull()) {
            // Internal consistency check.
            if (!ptrBuff.isFull())
                System.err.println("PtrBuffer is not full");
            // The split point for the next level up.
            slot = new Pair<>(bptNode.getId(), pair.cdr());
            if (debug)
                System.out.printf("Write(1): %d\n", bptNode.getId());
            if (debug)
                System.out.println(bptNode);
            if (debug)
                System.out.println("Slot = " + slot);
            mgr.put(bptNode);
            // No count increment needed.
            return true;
        }
        recBuff.add(r);
        bptNode.setCount(bptNode.getCount() + 1);
    }
    // If we get here, the input stream ran out before we finished a complete block.
    // Fix up block (remove the last record)
    Record r = recBuff.getHigh();
    recBuff.removeTop();
    bptNode.setCount(bptNode.getCount() - 1);
    slot = new Pair<>(bptNode.getId(), r);
    if (debug)
        System.out.printf("Write(2): %d\n", bptNode.getId());
    if (debug)
        System.out.println(bptNode);
    if (debug)
        System.out.println("Slot = " + slot);
    mgr.put(bptNode);
    return true;
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) PtrBuffer(org.apache.jena.tdb.base.buffer.PtrBuffer)

Example 23 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class TestRecordBufferPage method fill.

private static void fill(RecordBuffer rb, int... nums) {
    for (int num : nums) {
        Record rec = record(num);
        rb.add(rec);
    }
}
Also used : Record(org.apache.jena.tdb.base.record.Record)

Example 24 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class TestRecordBuffer method recBufferIterate05.

@Test
public void recBufferIterate05() {
    RecordBuffer rb = make(3, 5);
    Iterator<Record> iter = rb.iterator(intToRecord(1), null);
    same(iter, 2, 4, 6);
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordLib.intToRecord(org.apache.jena.tdb.base.record.RecordLib.intToRecord) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 25 with Record

use of org.apache.jena.tdb.base.record.Record in project jena by apache.

the class TestRecordBuffer method make.

private static RecordBuffer make(int n, int len) {
    RecordBuffer rb = new RecordBuffer(recordFactory, len);
    for (int i = 0; i < n; i++) {
        Record r = RecordLib.intToRecord(2 * i + 2);
        rb.add(r);
    }
    return rb;
}
Also used : Record(org.apache.jena.tdb.base.record.Record) RecordLib.intToRecord(org.apache.jena.tdb.base.record.RecordLib.intToRecord) RecordBuffer(org.apache.jena.tdb.base.buffer.RecordBuffer)

Aggregations

Record (org.apache.jena.tdb.base.record.Record)96 BaseTest (org.apache.jena.atlas.junit.BaseTest)25 Test (org.junit.Test)25 RecordLib.intToRecord (org.apache.jena.tdb.base.record.RecordLib.intToRecord)20 RecordBuffer (org.apache.jena.tdb.base.buffer.RecordBuffer)15 RangeIndex (org.apache.jena.tdb.index.RangeIndex)8 BPTreeRecords (org.apache.jena.tdb.index.bplustree.BPTreeRecords)5 NodeId (org.apache.jena.tdb.store.NodeId)5 NoSuchElementException (java.util.NoSuchElementException)4 Pair (org.apache.jena.atlas.lib.Pair)4 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)4 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)4 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)3 StorageException (org.apache.jena.tdb.base.StorageException)3 FileSet (org.apache.jena.tdb.base.file.FileSet)3 Location (org.apache.jena.tdb.base.file.Location)3 RecordBufferPage (org.apache.jena.tdb.base.recordbuffer.RecordBufferPage)3 Index (org.apache.jena.tdb.index.Index)3 BPlusTree (org.apache.jena.tdb.index.bplustree.BPlusTree)3 TupleIndexRecord (org.apache.jena.tdb.store.tupletable.TupleIndexRecord)3