use of io.questdb.griffin.SqlCompiler 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.SqlCompiler 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) {
}
}
}
}
use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.
the class LineTcpO3Test method test.
private void test(String ilpResourceName) throws Exception {
assertMemoryLeak(() -> {
long clientFd = Net.socketTcp(true);
Assert.assertTrue(clientFd >= 0);
long ilpSockAddr = Net.sockaddr(Net.parseIPv4("127.0.0.1"), lineConfiguration.getNetDispatcherConfiguration().getBindPort());
WorkerPool sharedWorkerPool = new WorkerPool(sharedWorkerPoolConfiguration);
try (LineTcpReceiver ignored = LineTcpReceiver.create(lineConfiguration, sharedWorkerPool, LOG, engine);
SqlCompiler compiler = new SqlCompiler(engine);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
SOCountDownLatch haltLatch = new SOCountDownLatch(1);
engine.setPoolListener((factoryType, thread, name, event, segment, position) -> {
if (factoryType == PoolListener.SRC_WRITER && event == PoolListener.EV_RETURN && Chars.equals(name, "cpu")) {
haltLatch.countDown();
}
});
sharedWorkerPool.assignCleaner(Path.CLEANER);
sharedWorkerPool.start(LOG);
TestUtils.assertConnect(clientFd, ilpSockAddr);
readGzResource(ilpResourceName);
Net.send(clientFd, resourceAddress, resourceSize);
Unsafe.free(resourceAddress, resourceSize, MemoryTag.NATIVE_DEFAULT);
haltLatch.await();
TestUtils.printSql(compiler, sqlExecutionContext, "select * from " + "cpu", sink);
readGzResource("selectAll1");
DirectUnboundedByteSink expectedSink = new DirectUnboundedByteSink(resourceAddress);
expectedSink.clear(resourceSize);
TestUtils.assertEquals(expectedSink.toString(), sink);
Unsafe.free(resourceAddress, resourceSize, MemoryTag.NATIVE_DEFAULT);
} finally {
engine.setPoolListener(null);
Net.close(clientFd);
Net.freeSockAddr(ilpSockAddr);
sharedWorkerPool.halt();
}
});
}
use of io.questdb.griffin.SqlCompiler in project invesdwin-context-persistence by subes.
the class QuestDBPerformanceTest method testQuestDbPerformance.
@Test
public void testQuestDbPerformance() throws InterruptedException, SqlException, IOException {
final File directory = new File(ContextProperties.getCacheDirectory(), QuestDBPerformanceTest.class.getSimpleName());
Files.deleteNative(directory);
Files.forceMkdir(directory);
final CairoConfiguration configuration = new DefaultCairoConfiguration(directory.getAbsolutePath());
final Instant writesStart = new Instant();
int i = 0;
final CairoEngine engine = new CairoEngine(configuration);
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table abc (value long, key timestamp) timestamp(key)", ctx);
try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "insert")) {
for (final FDate date : newValues()) {
final TableWriter.Row row = writer.newRow(date.millisValue());
row.putLong(0, date.millisValue());
row.append();
i++;
if (i % FLUSH_INTERVAL == 0) {
if (loopCheck.check()) {
printProgress("Writes", writesStart, i, VALUES);
}
writer.commit();
}
}
writer.commit();
}
printProgress("WritesFinished", writesStart, VALUES, VALUES);
}
readIterator(engine);
readGet(engine);
readGetLatest(engine);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("dtop table 'abc';", ctx);
}
engine.close();
Files.deleteNative(directory);
}
use of io.questdb.griffin.SqlCompiler in project invesdwin-context-persistence by subes.
the class QuestDBPerformanceTest method readGet.
private void readGet(final CairoEngine engine) throws InterruptedException, SqlException {
final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
final List<FDate> values = Lists.toList(newValues());
final Instant readsStart = new Instant();
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
for (int reads = 0; reads < READS; reads++) {
FDate prevValue = null;
int count = 0;
for (int i = 0; i < values.size(); i++) {
try (RecordCursorFactory factory = compiler.compile("abc WHERE key = cast(" + values.get(i).millisValue() + " AS TIMESTAMP) LIMIT 1", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final io.questdb.cairo.sql.Record record = cursor.getRecord();
Assertions.checkTrue(cursor.hasNext());
final FDate value = new FDate(record.getLong(0));
if (prevValue != null) {
Assertions.checkTrue(prevValue.isBefore(value));
}
prevValue = value;
count++;
}
}
}
Assertions.checkEquals(count, VALUES);
if (loopCheck.check()) {
printProgress("Gets", readsStart, VALUES * reads, VALUES * READS);
}
}
}
printProgress("GetsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Aggregations