use of io.questdb.griffin.SqlExecutionContext 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.SqlExecutionContext 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.SqlExecutionContext 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.SqlExecutionContext in project questdb by bluestreak01.
the class IODispatcherTest method testJsonQueryMultiThreaded.
@Test
public void testJsonQueryMultiThreaded() throws Exception {
final int threadCount = 4;
final int requestsPerThread = 500;
final String[][] requests = { { "GET /exec?query=xyz%20where%20sym%20%3D%20%27UDEYY%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "d9\r\n" + "{\"query\":\"xyz where sym = 'UDEYY'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"UDEYY\",0.15786635599554755],[\"UDEYY\",0.8445258177211064],[\"UDEYY\",0.5778947915182423]],\"count\":3}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27QEHBH%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "0114\r\n" + "{\"query\":\"xyz where sym = 'QEHBH'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"QEHBH\",0.4022810626779558],[\"QEHBH\",0.9038068796506872],[\"QEHBH\",0.05048190020054388],[\"QEHBH\",0.4149517697653501],[\"QEHBH\",0.44804689668613573]],\"count\":5}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27SXUXI%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "da\r\n" + "{\"query\":\"xyz where sym = 'SXUXI'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"SXUXI\",0.6761934857077543],[\"SXUXI\",0.38642336707855873],[\"SXUXI\",0.48558682958070665]],\"count\":3}\r\n" + "00\r\n" + "\r\n" }, { "GET /exec?query=xyz%20where%20sym%20%3D%20%27VTJWC%27 HTTP/1.1\r\n" + "Host: localhost:9001\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: max-age=0\r\n" + "Upgrade-Insecure-Requests: 1\r\n" + "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36\r\n" + "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3\r\n" + "Accept-Encoding: gzip, deflate, br\r\n" + "Accept-Language: en-GB,en-US;q=0.9,en;q=0.8\r\n" + "\r\n", "HTTP/1.1 200 OK\r\n" + "Server: questDB/1.0\r\n" + "Date: Thu, 1 Jan 1970 00:00:00 GMT\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/json; charset=utf-8\r\n" + "Keep-Alive: timeout=5, max=10000\r\n" + "\r\n" + "f4\r\n" + "{\"query\":\"xyz where sym = 'VTJWC'\",\"columns\":[{\"name\":\"sym\",\"type\":\"SYMBOL\"},{\"name\":\"d\",\"type\":\"DOUBLE\"}],\"dataset\":[[\"VTJWC\",0.3435685332942956],[\"VTJWC\",0.8258367614088108],[\"VTJWC\",0.437176959518218],[\"VTJWC\",0.7176053468281931]],\"count\":4}\r\n" + "00\r\n" + "\r\n" } };
new HttpQueryTestBuilder().withTempFolder(temp).withWorkerCount(threadCount).withHttpServerConfigBuilder(new HttpServerConfigurationBuilder()).withTelemetry(false).run((engine) -> {
final SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table xyz as (select rnd_symbol(10, 5, 5, 0) sym, rnd_double() d from long_sequence(30)), index(sym)", sqlExecutionContext);
final CyclicBarrier barrier = new CyclicBarrier(threadCount);
final CountDownLatch latch = new CountDownLatch(threadCount);
final AtomicInteger errorCount = new AtomicInteger(0);
for (int i = 0; i < threadCount; i++) {
new QueryThread(requests, requestsPerThread, barrier, latch, errorCount).start();
}
latch.await();
Assert.assertEquals(0, errorCount.get());
} catch (SqlException e) {
Assert.fail(e.getMessage());
}
});
}
use of io.questdb.griffin.SqlExecutionContext in project questdb by bluestreak01.
the class LineTcpConnectionContextTest method testTableParameterRetentionOnAddColumn.
@Test
public void testTableParameterRetentionOnAddColumn() throws Exception {
String table = "retention";
runInContext(() -> {
try (SqlCompiler compiler = new SqlCompiler(engine);
SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
compiler.compile("create table " + table + " (location SYMBOL, temperature DOUBLE, timestamp TIMESTAMP) timestamp(timestamp) partition by DAY WITH maxUncommittedRows=3, commitLag=250ms;", sqlExecutionContext);
} catch (SqlException ex) {
throw new RuntimeException(ex);
}
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, table)) {
Assert.assertEquals(3, reader.getMetadata().getMaxUncommittedRows());
Assert.assertEquals(250_000, reader.getMetadata().getCommitLag());
}
recvBuffer = table + ",location=us-midwest temperature=82 1465839830100400200\n" + table + ",location=us-midwest temperature=83 1465839830100500200\n" + table + ",location=us-eastcoast,city=york temperature=81 1465839830101400200\n" + table + ",location=us-midwest temperature=85 1465839830102300200\n" + table + ",location=us-eastcoast temperature=89 1465839830102400200\n" + table + ",location=us-eastcoast temperature=80 1465839830102400200\n" + table + ",location=us-westcost temperature=82 1465839830102500200\n";
do {
handleContextIO();
Assert.assertFalse(disconnected);
} while (recvBuffer.length() > 0);
closeContext();
String expected = "location\ttemperature\ttimestamp\tcity\n" + "us-midwest\t82.0\t2016-06-13T17:43:50.100400Z\t\n" + "us-midwest\t83.0\t2016-06-13T17:43:50.100500Z\t\n" + "us-eastcoast\t81.0\t2016-06-13T17:43:50.101400Z\tyork\n" + "us-midwest\t85.0\t2016-06-13T17:43:50.102300Z\t\n" + "us-eastcoast\t89.0\t2016-06-13T17:43:50.102400Z\t\n" + "us-eastcoast\t80.0\t2016-06-13T17:43:50.102400Z\t\n" + "us-westcost\t82.0\t2016-06-13T17:43:50.102500Z\t\n";
assertTable(expected, table);
try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, table)) {
Assert.assertEquals(3, reader.getMetadata().getMaxUncommittedRows());
Assert.assertEquals(250_000, reader.getMetadata().getCommitLag());
}
});
}
Aggregations