use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class MemoryLeakTest method populateUsersTable.
private void populateUsersTable(CairoEngine engine, int n) throws SqlException {
try (final SqlCompiler compiler = new SqlCompiler(engine);
final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null)) {
compiler.compile("create table users (sequence long, event binary, timestamp timestamp, id long) timestamp(timestamp)", executionContext);
long buffer = Unsafe.malloc(1024, MemoryTag.NATIVE_DEFAULT);
try {
try (TableWriter writer = engine.getWriter(executionContext.getCairoSecurityContext(), "users", "testing")) {
// time can go backwards if asked too quickly, add I to offset the chance (on mac M1 at least)
// call_j can yield a lower value than call_i thus resulting in an unordered
long baseTimestamp = Os.currentTimeMicros();
for (int i = 0; i < n; i++) {
// table, so we add i to make sure the timestamps are ordered
long sequence = 20 + i * 2L;
TableWriter.Row row = writer.newRow(baseTimestamp + i);
row.putLong(0, sequence);
row.putBin(1, buffer, 1024);
row.putLong(3, i);
row.append();
}
writer.commit();
}
} finally {
Unsafe.free(buffer, 1024, MemoryTag.NATIVE_DEFAULT);
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class DropTableTest method testDropBusyWriter.
@Test
public void testDropBusyWriter() throws Exception {
assertMemoryLeak(() -> {
CompiledQuery cc = compiler.compile("create table 'large table' (a int)", sqlExecutionContext);
Assert.assertEquals(CompiledQuery.CREATE_TABLE, cc.getType());
try (TableWriter ignored = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "large table", "testing")) {
compiler.compile("drop table 'large table'", sqlExecutionContext);
} catch (CairoException e) {
TestUtils.assertContains(e.getFlyweightMessage(), "Could not lock");
}
});
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class FirstDateGroupByFunctionFactoryTest method testFirstNull.
@Test
public void testFirstNull() throws SqlException {
compiler.compile("create table tab (f date)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
TableWriter.Row r = w.newRow();
r.append();
for (int i = 100; i > 10; i--) {
r = w.newRow();
r.putLong(0, rnd.nextLong());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(Numbers.LONG_NaN, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class FirstDateGroupByFunctionFactoryTest method testNonNull.
@Test
public void testNonNull() throws SqlException {
compiler.compile("create table tab (f date)", sqlExecutionContext);
final Rnd rnd = new Rnd();
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.putLong(0, rnd.nextLong());
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(4689592037643856L, record.getLong(0));
}
}
}
use of io.questdb.cairo.TableWriter in project questdb by bluestreak01.
the class FirstIntGroupByFunctionFactoryTest method testSomeNull.
@Test
public void testSomeNull() throws SqlException {
compiler.compile("create table tab (f int)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
if (i % 4 == 0) {
r.putInt(0, i);
}
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select first(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(100, record.getInt(0));
}
}
}
Aggregations