Search in sources :

Example 1 with SqlExecutionContext

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

the class TableReaderReloadBenchmark 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 test(f timestamp) timestamp (f) PARTITION BY DAY", sqlExecutionContext);
        } catch (SqlException e) {
            throw new ExceptionInInitializerError();
        }
    }
    Options opt = new OptionsBuilder().include(TableReaderReloadBenchmark.class.getSimpleName()).warmupIterations(2).measurementIterations(2).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 2 with SqlExecutionContext

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

the class TelemetryTest method testTelemetryConfigUpgrade.

@Test
public void testTelemetryConfigUpgrade() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            compiler.compile("CREATE TABLE " + TelemetryJob.configTableName + " (id long256, enabled boolean)", sqlExecutionContext);
            InsertStatement ist = compiler.compile("INSERT INTO " + TelemetryJob.configTableName + " values(CAST('0x01' AS LONG256), true)", sqlExecutionContext).getInsertStatement();
            InsertMethod im = ist.createMethod(sqlExecutionContext);
            im.execute();
            im.commit();
            im.close();
            ist.close();
            TelemetryJob telemetryJob = new TelemetryJob(engine, null);
            String expectedSql = "column	type	indexed	indexBlockCapacity	symbolCached	symbolCapacity	designated\n" + "id	LONG256	false	0	false	0	false\n" + "enabled	BOOLEAN	false	0	false	0	false\n" + "version	SYMBOL	false	256	true	128	false\n" + "os	SYMBOL	false	256	true	128	false\n" + "package	SYMBOL	false	256	true	128	false\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SHOW COLUMNS FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "id\tversion\n" + "0x01\t\n" + "0x01\tUnknown Version\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT id, version FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) InsertMethod(io.questdb.cairo.sql.InsertMethod) CairoEngine(io.questdb.cairo.CairoEngine) InsertStatement(io.questdb.cairo.sql.InsertStatement) Test(org.junit.Test) AbstractCairoTest(io.questdb.cairo.AbstractCairoTest)

Example 3 with SqlExecutionContext

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

the class TelemetryTest method testTelemetryUpdatesVersion.

@Test
public void testTelemetryUpdatesVersion() throws Exception {
    final AtomicReference<String> refVersion = new AtomicReference<>();
    BuildInformation buildInformation = new BuildInformation() {

        @Override
        public CharSequence getQuestDbVersion() {
            return refVersion.get();
        }

        @Override
        public CharSequence getJdkVersion() {
            return null;
        }

        @Override
        public CharSequence getCommitHash() {
            return null;
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public BuildInformation getBuildInformation() {
            return buildInformation;
        }
    };
    TestUtils.assertMemoryLeak(() -> {
        try (CairoEngine engine = new CairoEngine(configuration);
            SqlCompiler compiler = new SqlCompiler(engine, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1)) {
            refVersion.set("1.0");
            TelemetryJob telemetryJob = new TelemetryJob(engine, null);
            String os = System.getProperty(TelemetryJob.OS_NAME);
            String expectedSql = "count\n1\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "version\tos\n" + "1.0\t" + os + "\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
            telemetryJob = new TelemetryJob(engine, null);
            expectedSql = "count\n1\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            Misc.free(telemetryJob);
            refVersion.set("1.1");
            telemetryJob = new TelemetryJob(engine, null);
            expectedSql = "count\n2\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT count(*) FROM " + TelemetryJob.configTableName, sink, expectedSql);
            expectedSql = "version\tos\n" + "1.1\t" + os + "\n";
            TestUtils.assertSql(compiler, sqlExecutionContext, "SELECT version, os FROM " + TelemetryJob.configTableName + " LIMIT -1", sink, expectedSql);
            Misc.free(telemetryJob);
        }
    });
}
Also used : SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) 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 4 with SqlExecutionContext

use of io.questdb.griffin.SqlExecutionContext 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 5 with SqlExecutionContext

use of io.questdb.griffin.SqlExecutionContext 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)

Aggregations

SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)12 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)11 SqlCompiler (io.questdb.griffin.SqlCompiler)10 Test (org.junit.Test)7 SqlException (io.questdb.griffin.SqlException)6 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)3 CairoConfiguration (io.questdb.cairo.CairoConfiguration)3 CairoEngine (io.questdb.cairo.CairoEngine)3 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 BindVariableServiceImpl (io.questdb.griffin.engine.functions.bind.BindVariableServiceImpl)2 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)2 IntList (io.questdb.std.IntList)2 Runner (org.openjdk.jmh.runner.Runner)2 Options (org.openjdk.jmh.runner.options.Options)2 OptionsBuilder (org.openjdk.jmh.runner.options.OptionsBuilder)2 ColumnType (io.questdb.cairo.ColumnType)1 Function (io.questdb.cairo.sql.Function)1 InsertMethod (io.questdb.cairo.sql.InsertMethod)1 InsertStatement (io.questdb.cairo.sql.InsertStatement)1