use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class CompactMapTest method testValueAccess.
@Test
public void testValueAccess() throws Exception {
TestUtils.assertMemoryLeak(() -> {
final int N = 1000;
final Rnd rnd = new Rnd();
TestRecord.ArrayBinarySequence binarySequence = new TestRecord.ArrayBinarySequence();
CairoTestUtils.createTestTable(N, rnd, binarySequence);
BytecodeAssembler asm = new BytecodeAssembler();
try (TableReader reader = new TableReader(configuration, "x")) {
EntityColumnFilter entityColumnFilter = new EntityColumnFilter();
entityColumnFilter.of(reader.getMetadata().getColumnCount());
try (CompactMap map = new CompactMap(1024 * 1024, new SymbolAsStrTypes(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG).add(ColumnType.INT).add(ColumnType.SHORT).add(ColumnType.BYTE).add(ColumnType.FLOAT).add(ColumnType.DOUBLE).add(ColumnType.DATE).add(ColumnType.TIMESTAMP).add(ColumnType.BOOLEAN).add(ColumnType.getGeoHashTypeWithBits(5)).add(ColumnType.getGeoHashTypeWithBits(10)).add(ColumnType.getGeoHashTypeWithBits(20)).add(ColumnType.getGeoHashTypeWithBits(40)), N, 0.9, 1, Integer.MAX_VALUE)) {
RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
// this random will be populating values
Rnd rnd2 = new Rnd();
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
populateMapGeo(map, rnd2, cursor, sink);
cursor.toTop();
rnd2.reset();
long c = 0;
while (cursor.hasNext()) {
MapKey key = map.withKey();
key.put(record, sink);
MapValue value = key.findValue();
Assert.assertNotNull(value);
Assert.assertEquals(++c, value.getLong(0));
Assert.assertEquals(rnd2.nextInt(), value.getInt(1));
Assert.assertEquals(rnd2.nextShort(), value.getShort(2));
Assert.assertEquals(rnd2.nextByte(), value.getByte(3));
Assert.assertEquals(rnd2.nextFloat(), value.getFloat(4), 0.000001f);
Assert.assertEquals(rnd2.nextDouble(), value.getDouble(5), 0.000000001);
Assert.assertEquals(rnd2.nextLong(), value.getDate(6));
Assert.assertEquals(rnd2.nextLong(), value.getTimestamp(7));
Assert.assertEquals(rnd2.nextBoolean(), value.getBool(8));
Assert.assertEquals((byte) Math.abs(rnd2.nextByte()), value.getGeoByte(9));
Assert.assertEquals((short) Math.abs(rnd2.nextShort()), value.getGeoShort(10));
Assert.assertEquals(Math.abs(rnd2.nextInt()), value.getGeoInt(11));
Assert.assertEquals(Math.abs(rnd2.nextLong()), value.getGeoLong(12));
}
}
}
});
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class FastMapTest method testValueAccess.
@Test
public void testValueAccess() throws Exception {
TestUtils.assertMemoryLeak(() -> {
final int N = 1000;
final Rnd rnd = new Rnd();
TestRecord.ArrayBinarySequence binarySequence = new TestRecord.ArrayBinarySequence();
createTestTable(N, rnd, binarySequence);
BytecodeAssembler asm = new BytecodeAssembler();
try (TableReader reader = new TableReader(configuration, "x")) {
EntityColumnFilter entityColumnFilter = new EntityColumnFilter();
entityColumnFilter.of(reader.getMetadata().getColumnCount());
try (FastMap map = new FastMap(Numbers.SIZE_1MB, new SymbolAsStrTypes(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG).add(ColumnType.INT).add(ColumnType.SHORT).add(ColumnType.BYTE).add(ColumnType.FLOAT).add(ColumnType.DOUBLE).add(ColumnType.DATE).add(ColumnType.TIMESTAMP).add(ColumnType.BOOLEAN).add(ColumnType.getGeoHashTypeWithBits(5)).add(ColumnType.getGeoHashTypeWithBits(10)).add(ColumnType.getGeoHashTypeWithBits(20)).add(ColumnType.getGeoHashTypeWithBits(40)), N, 0.9f, 1)) {
RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
// this random will be populating values
Rnd rnd2 = new Rnd();
RecordCursor cursor = reader.getCursor();
Record record = cursor.getRecord();
populateMapGeo(map, rnd2, cursor, sink);
cursor.toTop();
rnd2.reset();
long c = 0;
while (cursor.hasNext()) {
MapKey key = map.withKey();
key.put(record, sink);
MapValue value = key.findValue();
Assert.assertNotNull(value);
Assert.assertEquals(++c, value.getLong(0));
Assert.assertEquals(rnd2.nextInt(), value.getInt(1));
Assert.assertEquals(rnd2.nextShort(), value.getShort(2));
Assert.assertEquals(rnd2.nextByte(), value.getByte(3));
Assert.assertEquals(rnd2.nextFloat(), value.getFloat(4), 0.000001f);
Assert.assertEquals(rnd2.nextDouble(), value.getDouble(5), 0.000000001);
Assert.assertEquals(rnd2.nextLong(), value.getDate(6));
Assert.assertEquals(rnd2.nextLong(), value.getTimestamp(7));
Assert.assertEquals(rnd2.nextBoolean(), value.getBool(8));
Assert.assertEquals((byte) Math.abs(rnd2.nextByte()), value.getGeoByte(9));
Assert.assertEquals((short) Math.abs(rnd2.nextShort()), value.getGeoShort(10));
Assert.assertEquals(Math.abs(rnd2.nextInt()), value.getGeoInt(11));
Assert.assertEquals(Math.abs(rnd2.nextLong()), value.getGeoLong(12));
}
}
}
});
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class TableReaderTest method testConcurrentReloadMultiplePartitions.
private void testConcurrentReloadMultiplePartitions(int partitionBy, long stride) throws Exception {
TestUtils.assertMemoryLeak(() -> {
final int N = 1024_0000;
// model table
try (TableModel model = new TableModel(configuration, "w", partitionBy).col("l", ColumnType.LONG).timestamp()) {
CairoTestUtils.create(model);
}
final int threads = 2;
final CyclicBarrier startBarrier = new CyclicBarrier(threads);
final CountDownLatch stopLatch = new CountDownLatch(threads);
final AtomicInteger errors = new AtomicInteger(0);
// start writer
new Thread(() -> {
try {
startBarrier.await();
long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T00:00:00.000Z");
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestampUs);
row.putLong(0, i);
row.append();
writer.commit();
timestampUs += stride;
}
}
} catch (Exception e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
stopLatch.countDown();
}
}).start();
// start reader
new Thread(() -> {
try {
startBarrier.await();
try (TableReader reader = new TableReader(configuration, "w")) {
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
sink.clear();
((Sinkable) record).toSink(sink);
TestUtils.assertEquals("TableReaderRecord [columnBase=0, recordIndex=-1]", sink);
do {
// we deliberately ignore result of reload()
// to create more race conditions
reader.reload();
cursor.toTop();
int count = 0;
while (cursor.hasNext()) {
if (count++ != record.getLong(0)) {
sink.clear();
sink.put("Test [count=").put(count--).put(", rec=").put(record.getLong(0)).put(']').put(',');
((Sinkable) record).toSink(sink);
Assert.fail(sink.toString());
}
}
if (count == N) {
break;
}
} while (true);
}
} catch (Throwable e) {
e.printStackTrace();
errors.incrementAndGet();
} finally {
stopLatch.countDown();
}
}).start();
Assert.assertTrue(stopLatch.await(120, TimeUnit.SECONDS));
Assert.assertEquals(0, errors.get());
// check that we had multiple partitions created during the test
try (TableReader reader = new TableReader(configuration, "w")) {
Assert.assertTrue(reader.getPartitionCount() > 10);
}
});
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class TableReaderTest method testRemoveDefaultPartition.
@Test
public void testRemoveDefaultPartition() throws Exception {
TestUtils.assertMemoryLeak(() -> {
int N = 100;
int N_PARTITIONS = 5;
long timestampUs = TimestampFormatUtils.parseTimestamp("2017-12-11T00:00:00.000Z");
long stride = 100;
int bandStride = 1000;
int totalCount = 0;
// model table
try (TableModel model = new TableModel(configuration, "w", PartitionBy.NONE).col("l", ColumnType.LONG).timestamp()) {
CairoTestUtils.create(model);
}
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int k = 0; k < N_PARTITIONS; k++) {
long band = k * bandStride;
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestampUs);
row.putLong(0, band + i);
row.append();
writer.commit();
timestampUs += stride;
}
timestampUs = Timestamps.addDays(Timestamps.floorDD(timestampUs), 1);
}
Assert.assertEquals(N * N_PARTITIONS, writer.size());
Assert.assertFalse(writer.removePartition(0));
Assert.assertEquals(N * N_PARTITIONS, writer.size());
}
// now open table reader having partition gap
try (TableReader reader = new TableReader(configuration, "w")) {
Assert.assertEquals(N * N_PARTITIONS, reader.size());
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
record.getLong(0);
totalCount++;
}
}
Assert.assertEquals(N * N_PARTITIONS, totalCount);
});
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class TableReaderTest method testReadLong256One.
@Test
public void testReadLong256One() {
try (TableModel model = new TableModel(configuration, "w", PartitionBy.DAY).col("l", ColumnType.LONG256).timestamp()) {
CairoTestUtils.create(model);
}
final int N = 1_000_000;
final Rnd rnd = new Rnd();
long timestamp = 0;
try (TableWriter writer = new TableWriter(configuration, "w")) {
for (int i = 0; i < N; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putLong256(0, "0x" + padHexLong(rnd.nextLong()));
row.append();
}
writer.commit();
}
rnd.reset();
final StringSink sink = new StringSink();
try (TableReader reader = new TableReader(configuration, "w")) {
final RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
int count = 0;
while (cursor.hasNext()) {
sink.clear();
record.getLong256(0, sink);
TestUtils.assertEquals("0x" + padHexLong(rnd.nextLong()), sink);
count++;
}
Assert.assertEquals(N, count);
}
}
Aggregations