Search in sources :

Example 6 with ByteArrayOS

use of com.sap.hadoop.ds.streams.Streams.ByteArrayOS in project SQLWindowing by hbutani.

the class PartitionedByteBasedSortedMap method getValue.

public int getValue(Writable key, Writable value) throws BaseException {
    LockUtils.lock(lock.readLock());
    try {
        DataOStream dos = Streams.dos.get();
        ByteArrayOS bos = dos.getUnderlyingStream();
        bos.reset();
        key.write(dos);
        int p = splitList.getPartition(bos.bytearray(), 0, bos.len());
        ByteBasedSortedMap mp = partitions.get(p);
        return mp.getValue(key, value);
    } catch (IOException ie) {
        throw new BaseException(ie);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : BaseException(com.sap.hadoop.ds.BaseException) ByteArrayOS(com.sap.hadoop.ds.streams.Streams.ByteArrayOS) DataOStream(com.sap.hadoop.ds.streams.Streams.DataOStream) IOException(java.io.IOException)

Example 7 with ByteArrayOS

use of com.sap.hadoop.ds.streams.Streams.ByteArrayOS in project SQLWindowing by hbutani.

the class PartitionedByteBasedSortedMap method put.

public void put(Writable key, Writable value) throws BaseException {
    LockUtils.lock(lock.writeLock());
    try {
        DataOStream dos = Streams.dos.get();
        ByteArrayOS bos = dos.getUnderlyingStream();
        bos.reset();
        key.write(dos);
        int p = splitList.getPartition(bos.bytearray(), 0, bos.len());
        ByteBasedSortedMap mp = bringInMemory(p);
        try {
            int prevSz = mp.size();
            mp.put(key, value);
            if (mp.size() > prevSz)
                currentSize++;
            fixStartPositions = true;
            persistRandom();
        } catch (MapFullException oe) {
            ByteBasedSortedMap[] parts = mp.split();
            //				System.out.println(parts[0]);
            //				System.out.println(parts[1]);
            partitions.set(p, parts[1]);
            partitions.add(p, parts[0]);
            byte[] b = parts[0].getLastKey();
            splitList.splitPartition(p, b, 0, b.length);
            put(key, value);
        }
    } catch (IOException ie) {
        throw new BaseException(ie);
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : BaseException(com.sap.hadoop.ds.BaseException) ByteArrayOS(com.sap.hadoop.ds.streams.Streams.ByteArrayOS) DataOStream(com.sap.hadoop.ds.streams.Streams.DataOStream) IOException(java.io.IOException)

Aggregations

ByteArrayOS (com.sap.hadoop.ds.streams.Streams.ByteArrayOS)7 DataOStream (com.sap.hadoop.ds.streams.Streams.DataOStream)7 BaseException (com.sap.hadoop.ds.BaseException)4 IOException (java.io.IOException)4