use of com.sap.hadoop.ds.BaseException in project SQLWindowing by hbutani.
the class ByteBasedSortedMap method getKey.
public void getKey(int i, Writable wObj) throws BaseException {
LockUtils.lock(lock.readLock());
try {
i = index(i);
DataIStream dis = Streams.dis.get();
ByteArrayIS bis = dis.getUnderlyingStream();
bis.setBuffer(bytes, keyOffsetsArray[i], keyOffsetsArray[i + 1]);
wObj.readFields(dis);
} catch (IOException ie) {
throw new BaseException(ie);
} finally {
lock.readLock().unlock();
}
}
use of com.sap.hadoop.ds.BaseException in project SQLWindowing by hbutani.
the class PartitionedByteBasedSortedMap method getIndex.
public int getIndex(Writable w) throws BaseException {
fixStartPositions();
LockUtils.lock(lock.readLock());
try {
DataOStream dos = Streams.dos.get();
ByteArrayOS bos = dos.getUnderlyingStream();
bos.reset();
w.write(dos);
int p = splitList.getPartition(bos.bytearray(), 0, bos.len());
ByteBasedSortedMap mp = partitions.get(p);
return mp.getIndex(w);
} catch (IOException ie) {
throw new BaseException(ie);
} finally {
lock.readLock().unlock();
}
}
use of com.sap.hadoop.ds.BaseException in project SQLWindowing by hbutani.
the class PartitionedByteBasedSortedMap method persist.
private ByteBasedSortedMap persist(int i) throws BaseException {
try {
ByteBasedSortedMap mp = partitions.get(i);
if (!(mp instanceof PersistentByteBasedSortedMap)) {
File f = File.createTempFile("wdw", null, dir);
mp = new PersistentByteBasedSortedMap(f, mp, comparator);
partitions.set(i, mp);
}
return mp;
} catch (IOException ie) {
throw new BaseException(ie);
}
}
use of com.sap.hadoop.ds.BaseException 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();
}
}
use of com.sap.hadoop.ds.BaseException 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();
}
}
Aggregations