Search in sources :

Example 1 with CompiledQuery

use of io.questdb.griffin.CompiledQuery 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) {
            }
        }
    }
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) BindVariableServiceImpl(io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl) ReaderOutOfDateException(io.questdb.cairo.sql.ReaderOutOfDateException) CompiledQuery(io.questdb.griffin.CompiledQuery) Test(org.junit.Test)

Example 2 with CompiledQuery

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

the class ImportIODispatcherTest method testImportMisDetectsTimestampColumn.

private void testImportMisDetectsTimestampColumn(HttpServerConfigurationBuilder serverConfigBuilder, int rowCount) throws Exception {
    new HttpQueryTestBuilder().withTempFolder(temp).withWorkerCount(1).withHttpServerConfigBuilder(serverConfigBuilder).withTelemetry(false).run((engine) -> {
        setupSql(engine);
        compiler.compile("create table trips(" + "timestamp TIMESTAMP," + "str STRING," + "i STRING" + ") timestamp(timestamp)", sqlExecutionContext);
        String request = PostHeader.replace("name=trips", "name=trips&skipLev=true") + Request1DataHeader + generateImportCsv(0, rowCount, "aaaaaaaaaaaaaaaaa,22222222222222222222,33333333333333333") + Request1SchemaPart;
        new SendAndReceiveRequestBuilder().withExpectSendDisconnect(true).execute(request, "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" + "12\r\n" + "not a timestamp ''\r\n" + "00\r\n" + "\r\n");
        CompiledQuery compiledQuery = compiler.compile("insert into trips values (" + "'2021-07-20T00:01:00', 'ABC', 'DEF'" + ")", sqlExecutionContext);
        final InsertStatement insertStatement = compiledQuery.getInsertStatement();
        try (InsertMethod insertMethod = insertStatement.createMethod(sqlExecutionContext)) {
            insertMethod.execute();
            insertMethod.commit();
        }
        compiler.close();
    });
}
Also used : InsertMethod(io.questdb.cairo.sql.InsertMethod) CompiledQuery(io.questdb.griffin.CompiledQuery) InsertStatement(io.questdb.cairo.sql.InsertStatement)

Example 3 with CompiledQuery

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

the class TestUtils method insert.

public static void insert(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, CharSequence insertSql) throws SqlException {
    CompiledQuery compiledQuery = compiler.compile(insertSql, sqlExecutionContext);
    Assert.assertNotNull(compiledQuery.getInsertStatement());
    final InsertStatement insertStatement = compiledQuery.getInsertStatement();
    try (InsertMethod insertMethod = insertStatement.createMethod(sqlExecutionContext)) {
        insertMethod.execute();
        insertMethod.commit();
    }
}
Also used : CompiledQuery(io.questdb.griffin.CompiledQuery)

Aggregations

CompiledQuery (io.questdb.griffin.CompiledQuery)3 InsertMethod (io.questdb.cairo.sql.InsertMethod)1 InsertStatement (io.questdb.cairo.sql.InsertStatement)1 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)1 RecordCursor (io.questdb.cairo.sql.RecordCursor)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 SqlCompiler (io.questdb.griffin.SqlCompiler)1 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)1 Test (org.junit.Test)1