Search in sources :

Example 16 with SqlCompiler

use of io.questdb.griffin.SqlCompiler in project invesdwin-context-persistence by subes.

the class QuestDBPerformanceTest method readGetLatest.

private void readGetLatest(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++) {
                // ORDER BY key DESC is horribly slow (90/s), SELECT max works better
                try (RecordCursorFactory factory = compiler.compile("SELECT max(value) FROM 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++;
                        if (loopCheck.check()) {
                            printProgress("GetLatests", readsStart, VALUES * reads + count, VALUES * READS);
                        }
                    }
                }
            }
            Assertions.checkEquals(count, VALUES);
        }
    }
    printProgress("GetLatestsFinished", readsStart, VALUES * READS, VALUES * READS);
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) Instant(de.invesdwin.util.time.Instant) LoopInterruptedCheck(de.invesdwin.util.concurrent.loop.LoopInterruptedCheck) FDate(de.invesdwin.util.time.date.FDate)

Example 17 with SqlCompiler

use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.

the class IODispatcherTest method testJsonQueryGeoHashColumnChars.

@Test
public void testJsonQueryGeoHashColumnChars() throws Exception {
    new HttpQueryTestBuilder().withWorkerCount(1).withHttpServerConfigBuilder(new HttpServerConfigurationBuilder().withSendBufferSize(16 * 1024).withConfiguredMaxQueryResponseRowLimit(configuredMaxQueryResponseRowLimit)).withTempFolder(temp).run(engine -> {
        SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table y as (\n" + "select\n" + "cast(rnd_str(null, 'questdb1234567890', 'u10m99dd3pbj') as geohash(1c)) geo1,\n" + "cast(rnd_str(null, 'questdb1234567890', 'u10m99dd3pbj') as geohash(3c)) geo2,\n" + "cast(rnd_str(null, 'questdb1234567890', 'u10m99dd3pbj') as geohash(6c)) geo4,\n" + "cast(rnd_str(null, 'questdb1234567890', 'u10m99dd3pbj') as geohash(12c)) geo8," + "cast(rnd_str(null, 'questdb1234567890', 'u10m99dd3pbj') as geohash(1b)) geo01\n" + "from long_sequence(3)\n" + ")", executionContext);
            String request = "SELECT+*+FROM+y";
            new SendAndReceiveRequestBuilder().executeWithStandardHeaders("GET /query?query=" + request + " HTTP/1.1\r\n", "0166\r\n" + "{\"query\":\"SELECT * FROM y\",\"columns\":[" + "{\"name\":\"geo1\",\"type\":\"GEOHASH(1c)\"}," + "{\"name\":\"geo2\",\"type\":\"GEOHASH(3c)\"}," + "{\"name\":\"geo4\",\"type\":\"GEOHASH(6c)\"}," + "{\"name\":\"geo8\",\"type\":\"GEOHASH(12c)\"}," + "{\"name\":\"geo01\",\"type\":\"GEOHASH(1b)\"}" + "],\"dataset\":[" + "[null,null,\"questd\",\"u10m99dd3pbj\",\"1\"]," + "[\"u\",\"u10\",\"questd\",null,\"1\"]," + "[\"q\",\"u10\",\"questd\",\"questdb12345\",\"1\"]" + "],\"count\":3}\r\n" + "00\r\n" + "\r\n");
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler)

Example 18 with SqlCompiler

use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.

the class IODispatcherTest method testImportEpochTimestamp.

@Test
public void testImportEpochTimestamp() throws Exception {
    new HttpQueryTestBuilder().withTempFolder(temp).withWorkerCount(2).withHttpServerConfigBuilder(new HttpServerConfigurationBuilder().withNetwork(NetworkFacadeImpl.INSTANCE).withDumpingTraffic(false).withAllowDeflateBeforeSend(false).withHttpProtocolVersion("HTTP/1.1 ").withServerKeepAlive(true)).run((engine) -> {
        SqlExecutionContextImpl executionContext = new SqlExecutionContextImpl(engine, 1);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table test (ts timestamp, value int) timestamp(ts) partition by DAY", executionContext);
            sendAndReceive(NetworkFacadeImpl.INSTANCE, "POST /upload?name=test HTTP/1.1\r\n" + "Host: localhost:9000\r\n" + "User-Agent: curl/7.71.1\r\n" + "Accept: */*\r\n" + "Content-Length: 372\r\n" + "Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryOsOAD9cPKyHuxyBV\r\n" + "\r\n" + "------WebKitFormBoundaryOsOAD9cPKyHuxyBV\r\n" + "Content-Disposition: form-data; name=\"data\"\r\n" + "\r\n" + "100000000,1000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "100000001,2000\r\n" + "\r\n" + "------WebKitFormBoundaryOsOAD9cPKyHuxyBV--", "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: text/plain; charset=utf-8\r\n" + "\r\n" + "0507\r\n" + "+-----------------------------------------------------------------------------------------------------------------+\r\n" + "|      Location:  |                                              test  |        Pattern  | Locale  |      Errors  |\r\n" + "|   Partition by  |                                               DAY  |                 |         |              |\r\n" + "|      Timestamp  |                                                ts  |                 |         |              |\r\n" + "+-----------------------------------------------------------------------------------------------------------------+\r\n" + "|   Rows handled  |                                                11  |                 |         |              |\r\n" + "|  Rows imported  |                                                11  |                 |         |              |\r\n" + "+-----------------------------------------------------------------------------------------------------------------+\r\n" + "|              0  |                                                ts  |                TIMESTAMP  |           0  |\r\n" + "|              1  |                                             value  |                      INT  |           0  |\r\n" + "+-----------------------------------------------------------------------------------------------------------------+\r\n" + "\r\n" + "00\r\n" + "\r\n", 1, 0, false, true);
            StringSink sink = new StringSink();
            TestUtils.assertSql(compiler, executionContext, "test", sink, "ts\tvalue\n" + "1970-01-01T00:01:40.000000Z\t1000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n" + "1970-01-01T00:01:40.000001Z\t2000\n");
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) StringSink(io.questdb.std.str.StringSink)

Example 19 with SqlCompiler

use of io.questdb.griffin.SqlCompiler 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());
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SqlException(io.questdb.griffin.SqlException) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) CountDownLatch(java.util.concurrent.CountDownLatch) CyclicBarrier(java.util.concurrent.CyclicBarrier)

Example 20 with SqlCompiler

use of io.questdb.griffin.SqlCompiler in project questdb by bluestreak01.

the class ImportIODispatcherTest method setupSql.

private void setupSql(CairoEngine engine) {
    compiler = new SqlCompiler(engine);
    BindVariableServiceImpl bindVariableService = new BindVariableServiceImpl(engine.getConfiguration());
    sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, bindVariableService, null, -1, null);
    bindVariableService.clear();
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)

Aggregations

SqlCompiler (io.questdb.griffin.SqlCompiler)25 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)21 Test (org.junit.Test)11 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)10 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)8 CairoEngine (io.questdb.cairo.CairoEngine)7 RecordCursor (io.questdb.cairo.sql.RecordCursor)6 SqlException (io.questdb.griffin.SqlException)6 CairoConfiguration (io.questdb.cairo.CairoConfiguration)5 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)5 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)4 Instant (de.invesdwin.util.time.Instant)4 FDate (de.invesdwin.util.time.date.FDate)4 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)4 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)3 TableWriter (io.questdb.cairo.TableWriter)3 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)3 FilesFacade (io.questdb.std.FilesFacade)3 FilesFacadeImpl (io.questdb.std.FilesFacadeImpl)3 Record (io.questdb.cairo.sql.Record)2