Search in sources :

Example 6 with SqlExecutionContextImpl

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

the class TableWriteBenchmark method main.

public static void main(String[] args) throws RunnerException {
    try (CairoEngine engine = new CairoEngine(configuration)) {
        SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table if not exists test1(f long) ", sqlExecutionContext);
            compiler.compile("create table if not exists test2(f timestamp) timestamp (f)", sqlExecutionContext);
            compiler.compile("create table if not exists test3(f timestamp) timestamp (f) PARTITION BY DAY", sqlExecutionContext);
        } catch (SqlException e) {
            e.printStackTrace();
        }
    }
    Options opt = new OptionsBuilder().include(TableWriteBenchmark.class.getSimpleName()).warmupIterations(5).measurementIterations(5).forks(1).build();
    new Runner(opt).run();
    LogFactory.INSTANCE.haltThread();
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) Options(org.openjdk.jmh.runner.options.Options) Runner(org.openjdk.jmh.runner.Runner) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) SqlException(io.questdb.griffin.SqlException) OptionsBuilder(org.openjdk.jmh.runner.options.OptionsBuilder)

Example 7 with SqlExecutionContextImpl

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

the class DataFrameRecordCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 100;
        // separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        final String[] symbols = new String[N];
        final int M = 1000;
        final long increment = 1000000 * 60L * 4;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        rnd.reset();
        // prepare the data
        long timestamp = 0;
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < M; i++) {
                TableWriter.Row row = writer.newRow(timestamp += increment);
                row.putStr(0, rnd.nextChars(20));
                row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
                row.putInt(2, rnd.nextInt());
                row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
                row.append();
            }
            writer.commit();
        }
        try (CairoEngine engine = new CairoEngine(configuration)) {
            String value = symbols[N - 10];
            int columnIndex;
            int symbolKey;
            RecordMetadata metadata;
            try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
                columnIndex = reader.getMetadata().getColumnIndexQuiet("b");
                symbolKey = reader.getSymbolMapReader(columnIndex).keyOf(value);
                metadata = GenericRecordMetadata.copyOf(reader.getMetadata());
            }
            SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(columnIndex, symbolKey, true, BitmapIndexReader.DIR_FORWARD, null);
            FullFwdDataFrameCursorFactory dataFrameFactory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION);
            // entity index
            final IntList columnIndexes = new IntList();
            for (int i = 0, n = metadata.getColumnCount(); i < n; i++) {
                columnIndexes.add(i);
            }
            DataFrameRecordCursorFactory factory = new DataFrameRecordCursorFactory(metadata, dataFrameFactory, symbolIndexRowCursorFactory, false, null, false, columnIndexes, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    TestUtils.assertEquals(value, record.getSym(1));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) IntList(io.questdb.std.IntList) RecordMetadata(io.questdb.cairo.sql.RecordMetadata) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 8 with SqlExecutionContextImpl

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

Example 9 with SqlExecutionContextImpl

use of io.questdb.griffin.SqlExecutionContextImpl 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 10 with SqlExecutionContextImpl

use of io.questdb.griffin.SqlExecutionContextImpl 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();
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) WorkerPool(io.questdb.mp.WorkerPool) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) DirectUnboundedByteSink(io.questdb.std.str.DirectUnboundedByteSink) SOCountDownLatch(io.questdb.mp.SOCountDownLatch)

Aggregations

SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)22 SqlCompiler (io.questdb.griffin.SqlCompiler)21 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)11 Test (org.junit.Test)9 CairoEngine (io.questdb.cairo.CairoEngine)7 RecordCursor (io.questdb.cairo.sql.RecordCursor)7 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)6 CairoConfiguration (io.questdb.cairo.CairoConfiguration)5 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)5 SqlException (io.questdb.griffin.SqlException)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 Record (io.questdb.cairo.sql.Record)3 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)2 WorkerPool (io.questdb.mp.WorkerPool)2 Rnd (io.questdb.std.Rnd)2