use of io.questdb.cairo.sql.RecordCursor 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);
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TableReaderTest method testReaderAndWriterRace.
@Test
public void testReaderAndWriterRace() throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE)) {
CairoTestUtils.create(model.timestamp());
}
CountDownLatch stopLatch = new CountDownLatch(2);
CyclicBarrier barrier = new CyclicBarrier(2);
int count = 1000000;
AtomicInteger reloadCount = new AtomicInteger(0);
try (TableWriter writer = new TableWriter(configuration, "x");
TableReader reader = new TableReader(configuration, "x")) {
new Thread(() -> {
try {
barrier.await();
for (int i = 0; i < count; i++) {
TableWriter.Row row = writer.newRow(i);
row.append();
writer.commit();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
stopLatch.countDown();
}
}).start();
new Thread(() -> {
try {
barrier.await();
int max = 0;
RecordCursor cursor = reader.getCursor();
while (max < count) {
if (reader.reload()) {
reloadCount.incrementAndGet();
cursor.toTop();
int localCount = 0;
while (cursor.hasNext()) {
localCount++;
}
if (localCount > max) {
max = localCount;
}
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
stopLatch.countDown();
}
}).start();
stopLatch.await();
Assert.assertTrue(reloadCount.get() > 0);
}
});
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TableReaderTest method testTableCursor.
private void testTableCursor(long inc) throws NumericException {
Rnd rnd = new Rnd();
int N = 100;
long ts = TimestampFormatUtils.parseTimestamp("2013-03-04T00:00:00.000Z") / 1000;
long blob = allocBlob();
try {
testAppend(rnd, configuration, ts, N, inc, blob, 0);
final LongList rows = new LongList();
try (TableReader reader = new TableReader(configuration, "all")) {
Assert.assertEquals(N, reader.size());
RecordCursor cursor = reader.getCursor();
final Record record = cursor.getRecord();
assertCursor(cursor, ts, inc, blob, N, BATCH1_ASSERTER);
cursor.toTop();
while (cursor.hasNext()) {
rows.add(record.getRowId());
}
Rnd exp = new Rnd();
final Record rec = cursor.getRecordB();
for (int i = 0, n = rows.size(); i < n; i++) {
cursor.recordAt(rec, rows.getQuick(i));
BATCH1_ASSERTER.assertRecord(rec, exp, ts += inc, blob);
}
}
} finally {
freeBlob(blob);
}
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TruncateTest method testTruncateOpenReader.
@Test
public void testTruncateOpenReader() throws Exception {
assertMemoryLeak(() -> {
createX(1_000_000);
assertQuery("count\n" + "1000000\n", "select count() from x", null, false, true);
try (RecordCursorFactory factory = compiler.compile("select * from x", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
record.getInt(0);
record.getSym(1);
record.getDouble(2);
}
}
}
compiler.compile("truncate table 'x'", sqlExecutionContext);
});
}
use of io.questdb.cairo.sql.RecordCursor in project questdb by bluestreak01.
the class TruncateTest method testDropTableWithCachedPlan.
private void testDropTableWithCachedPlan(String query) throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table y as (" + "select timestamp_sequence(0, 1000000000) timestamp," + " rnd_symbol('a','b',null) symbol1 " + " from long_sequence(10)" + ") timestamp (timestamp)", sqlExecutionContext);
try (RecordCursorFactory factory = compiler.compile(query, sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
sink.clear();
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
}
compiler.compile("drop table y", sqlExecutionContext);
compiler.compile("create table y as ( " + " select " + " timestamp_sequence('1970-01-01T02:30:00.000000Z', 1000000000L) timestamp " + " ,rnd_str('a','b','c', 'd', 'e', 'f',null) symbol2" + " ,rnd_str('a','b',null) symbol1" + " from long_sequence(10)" + ")", sqlExecutionContext);
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, printer);
Assert.fail();
} catch (ReaderOutOfDateException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "cannot be used because table schema has changed [table='y']");
}
}
});
}
Aggregations