Search in sources :

Example 21 with SqlCompiler

use of io.questdb.griffin.SqlCompiler 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());
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) SqlException(io.questdb.griffin.SqlException) Test(org.junit.Test)

Example 22 with SqlCompiler

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

the class TimestampSequenceFunctionFactoryTest method setUp2.

@BeforeClass
public static void setUp2() {
    engine = new CairoEngine(new StaticClockCairoConfiguration(root));
    compiler = new SqlCompiler(engine);
    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) CairoEngine(io.questdb.cairo.CairoEngine) BeforeClass(org.junit.BeforeClass)

Example 23 with SqlCompiler

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

the class TelemetryTest method testTelemetryCanDeleteTableWhenDisabled.

@Test
public void testTelemetryCanDeleteTableWhenDisabled() throws Exception {
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public TelemetryConfiguration getTelemetryConfiguration() {
            return new DefaultTelemetryConfiguration() {

                @Override
                public boolean getEnabled() {
                    return false;
                }
            };
        }
    };
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            TelemetryJob ignored = new TelemetryJob(engine);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            try {
                compiler.compile("drop table telemetry", sqlExecutionContext);
                Assert.fail();
            } catch (SqlException e) {
                TestUtils.assertContains(e.getFlyweightMessage(), "table 'telemetry' does not exist");
            }
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) SqlException(io.questdb.griffin.SqlException) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 24 with SqlCompiler

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

the class TxSerializerTest method setUpStatic.

@BeforeClass
public static void setUpStatic() {
    setCairoStatic();
    compiler = new SqlCompiler(engine);
    BindVariableServiceImpl bindVariableService = new BindVariableServiceImpl(configuration);
    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)

Example 25 with SqlCompiler

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

the class QuestDBPerformanceTest method readIterator.

private void readIterator(final CairoEngine engine) throws InterruptedException, SqlException {
    final LoopInterruptedCheck loopCheck = new LoopInterruptedCheck(Duration.ONE_SECOND);
    final Instant readsStart = new Instant();
    final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 1);
    try (SqlCompiler compiler = new SqlCompiler(engine)) {
        for (int reads = 1; reads <= READS; reads++) {
            FDate prevValue = null;
            int count = 0;
            try (RecordCursorFactory factory = compiler.compile("abc ORDER BY key ASC", ctx).getRecordCursorFactory()) {
                try (RecordCursor cursor = factory.getCursor(ctx)) {
                    final io.questdb.cairo.sql.Record record = cursor.getRecord();
                    while (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("Reads", readsStart, VALUES * reads, VALUES * READS);
            }
        }
    }
    printProgress("ReadsFinished", 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)

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