use of io.questdb.cairo.vm.api.MemoryR in project questdb by bluestreak01.
the class CompactMapTest method testUnableToFindFreeSlot.
@Test
public void testUnableToFindFreeSlot() {
// test what happens when map runs out of free slots while trying to
// reshuffle "foreign" entries out of the way
Rnd rnd = new Rnd();
// these have to be power of two for on the limit testing
// QMap will round capacity to next highest power of two!
int N = 256;
int M = 32;
// string is always a number and this number will be hash code of string.
class MockHash implements CompactMap.HashFunction {
@Override
public long hash(MemoryR mem, long offset, long size) {
// we have single key field, which is string
// the offset of string is 8 bytes for key cell + 4 bytes for string length, total is 12
char c = mem.getChar(offset + 12);
return c - '0';
}
}
StringSink sink = new StringSink();
// tweak capacity in such a way that we only have one spare slot before resize is needed
// this way algo that shuffles "foreign" slots away should face problems
double loadFactor = 0.9999999;
try (CompactMap map = new CompactMap(1024 * 1024, new SingleColumnType(ColumnType.STRING), new SingleColumnType(ColumnType.LONG), (long) (N * loadFactor), loadFactor, new MockHash(), 1, Integer.MAX_VALUE)) {
// assert that key capacity is what we expect, otherwise this test would be useless
Assert.assertEquals(N, map.getActualCapacity());
testUnableToFindFreeSlot0(rnd, N, M, sink, map);
map.clear();
rnd.reset();
testUnableToFindFreeSlot0(rnd, N, M, sink, map);
}
}
use of io.questdb.cairo.vm.api.MemoryR in project questdb by bluestreak01.
the class TableReader method avgDouble.
public double avgDouble(int columnIndex) {
double result = 0;
long countTotal = 0;
for (int i = 0; i < partitionCount; i++) {
openPartition(i);
final int base = getColumnBase(i);
final int index = getPrimaryColumnIndex(base, columnIndex);
final MemoryR column = columns.getQuick(index);
if (column != null) {
final long count = column.getPageSize() / Double.BYTES;
for (int pageIndex = 0, pageCount = column.getPageCount(); pageIndex < pageCount; pageIndex++) {
result += Vect.avgDouble(column.getPageAddress(pageIndex), count);
countTotal++;
}
}
}
if (countTotal == 0) {
return 0;
}
return result / countTotal;
}
use of io.questdb.cairo.vm.api.MemoryR in project questdb by bluestreak01.
the class TableReader method maxDouble.
public double maxDouble(int columnIndex) {
double max = Double.NEGATIVE_INFINITY;
for (int i = 0; i < partitionCount; i++) {
openPartition(i);
final int base = getColumnBase(i);
final int index = getPrimaryColumnIndex(base, columnIndex);
final MemoryR column = columns.getQuick(index);
if (column != null) {
final long count = column.getPageSize() / Double.BYTES;
for (int pageIndex = 0, pageCount = column.getPageCount(); pageIndex < pageCount; pageIndex++) {
long a = column.getPageAddress(pageIndex);
double x = Vect.maxDouble(a, count);
if (x > max) {
max = x;
}
}
}
}
return max;
}
use of io.questdb.cairo.vm.api.MemoryR in project questdb by bluestreak01.
the class TableReader method sumDouble.
public double sumDouble(int columnIndex) {
double result = 0;
for (int i = 0; i < partitionCount; i++) {
openPartition(i);
final int base = getColumnBase(i);
final int index = getPrimaryColumnIndex(base, columnIndex);
final MemoryR column = columns.getQuick(index);
if (column != null) {
final long count = column.getPageSize() / Double.BYTES;
for (int pageIndex = 0, pageCount = column.getPageCount(); pageIndex < pageCount; pageIndex++) {
long a = column.getPageAddress(pageIndex);
result += Vect.sumDouble(a, count);
}
}
}
return result;
}
use of io.questdb.cairo.vm.api.MemoryR in project questdb by bluestreak01.
the class TableReader method createBitmapIndexReaderAt.
private BitmapIndexReader createBitmapIndexReaderAt(int globalIndex, int columnBase, int columnIndex, int direction, long txn) {
BitmapIndexReader reader;
if (!metadata.isColumnIndexed(columnIndex)) {
throw CairoException.instance(0).put("Not indexed: ").put(metadata.getColumnName(columnIndex));
}
MemoryR col = columns.getQuick(globalIndex);
if (col instanceof NullColumn) {
if (direction == BitmapIndexReader.DIR_BACKWARD) {
reader = new BitmapIndexBwdNullReader();
bitmapIndexes.setQuick(globalIndex, reader);
} else {
reader = new BitmapIndexFwdNullReader();
bitmapIndexes.setQuick(globalIndex + 1, reader);
}
} else {
Path path = pathGenPartitioned(getPartitionIndex(columnBase));
try {
if (direction == BitmapIndexReader.DIR_BACKWARD) {
reader = new BitmapIndexBwdReader(configuration, path, metadata.getColumnName(columnIndex), getColumnTop(columnBase, columnIndex), txn);
bitmapIndexes.setQuick(globalIndex, reader);
} else {
reader = new BitmapIndexFwdReader(configuration, path, metadata.getColumnName(columnIndex), getColumnTop(columnBase, columnIndex), txn);
bitmapIndexes.setQuick(globalIndex + 1, reader);
}
} finally {
path.trimTo(rootLen);
}
}
return reader;
}
Aggregations