use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.
the class WhereClauseParserTest method setUp1.
@Before
public void setUp1() {
CairoEngine engine = new CairoEngine(configuration);
bindVariableService = new BindVariableServiceImpl(configuration);
compiler = new SqlCompiler(new CairoEngine(configuration));
sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null, -1, null);
}
use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.
the class MemoryLeakTest method testQuestDbForLeaks.
@Test
public void testQuestDbForLeaks() throws Exception {
assertMemoryLeak(() -> {
int N = 1_000_000;
populateUsersTable(engine, N);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
final BindVariableService bindVariableService = new BindVariableServiceImpl(configuration);
bindVariableService.setLong("low", 0L);
bindVariableService.setLong("high", 0L);
try (final SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null)) {
StringSink sink = new StringSink();
sink.clear();
sink.put("users");
sink.put(" latest by id where sequence > :low and sequence < :high");
try (RecordCursorFactory rcf = compiler.compile(sink, executionContext).getRecordCursorFactory()) {
bindVariableService.setLong("low", 0);
bindVariableService.setLong("high", N + 1);
Misc.free(rcf.getCursor(executionContext));
}
}
} finally {
Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
engine.clear();
Assert.assertEquals(Unsafe.getMemUsed(), getUsed());
}
});
}
use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl 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.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.
the class LineTcpReceiverTest method testWithColumnAsReservedKeyword.
@Test
public void testWithColumnAsReservedKeyword() throws Exception {
try (SqlCompiler compiler = new SqlCompiler(engine);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null, -1, null)) {
String expected = "out\ttimestamp\tin\n" + "1.0\t1989-12-31T23:26:40.000000Z\tNaN\n" + "NaN\t1990-01-01T00:00:00.000000Z\t2.0\n" + "NaN\t1990-01-01T02:13:20.000000Z\t3.0\n" + "NaN\t1990-01-01T05:00:00.000000Z\t4.0\n";
runInContext((receiver) -> {
String lineData = "up out=1.0 631150000000000000\n" + "up in=2.0 631152000000000000\n" + "up in=3.0 631160000000000000\n" + "up in=4.0 631170000000000000\n";
sendLinger(receiver, lineData, "up");
});
TestUtils.assertSql(compiler, sqlExecutionContext, "up", sink, expected);
}
}
use of io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl in project questdb by bluestreak01.
the class LineTcpReceiverTest method testTableTableIdChangedOnRecreate.
@Test
public void testTableTableIdChangedOnRecreate() throws Exception {
try (SqlCompiler compiler = new SqlCompiler(engine);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, new BindVariableServiceImpl(configuration), null, -1, null)) {
compiler.compile("create table weather as (" + "select x as windspeed," + "x*2 as timetocycle, " + "cast(x as timestamp) as ts " + "from long_sequence(2)) timestamp(ts) ", sqlExecutionContext);
CompiledQuery cq = compiler.compile("weather", sqlExecutionContext);
try (RecordCursorFactory cursorFactory = cq.getRecordCursorFactory()) {
try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
TestUtils.assertEquals("windspeed\ttimetocycle\tts\n" + "1\t2\t1970-01-01T00:00:00.000001Z\n" + "2\t4\t1970-01-01T00:00:00.000002Z\n", sink);
}
compiler.compile("drop table weather", sqlExecutionContext);
runInContext((receiver) -> {
String lineData = "weather windspeed=1.0 631150000000000000\n" + "weather windspeed=2.0 631152000000000000\n" + "weather timetocycle=0.0,windspeed=3.0 631160000000000000\n" + "weather windspeed=4.0 631170000000000000\n";
sendLinger(receiver, lineData, "weather");
});
try (RecordCursor cursor = cursorFactory.getCursor(sqlExecutionContext)) {
TestUtils.printCursor(cursor, cursorFactory.getMetadata(), true, sink, printer);
Assert.fail();
} catch (ReaderOutOfDateException ignored) {
}
}
}
}
Aggregations