Search in sources :

Example 6 with SqlCompiler

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

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

the class SampleByTest method testSampleFillLinearConstructorFail.

@Test
public void testSampleFillLinearConstructorFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        FilesFacade ff = new FilesFacadeImpl() {

            int count = 4;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext);
                    Assert.fail();
                } catch (SqlException e) {
                    Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) SqlException(io.questdb.griffin.SqlException) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 8 with SqlCompiler

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

the class SampleByTest method testSampleFillLinearFail.

@Test
public void testSampleFillLinearFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " rnd_double(0)*100 a," + " rnd_symbol(5,4,4,1) b," + " timestamp_sequence(172800000000, 3600000000) k" + " from" + " long_sequence(20000000)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        FilesFacade ff = new FilesFacadeImpl() {

            int count = 10;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    try (RecordCursorFactory factory = compiler.compile("select b, sum(a), k from x sample by 3h fill(linear)", sqlExecutionContext).getRecordCursorFactory()) {
                        // with mmap count = 5 we should get failure in cursor
                        factory.getCursor(sqlExecutionContext);
                    }
                    Assert.fail();
                } catch (CairoException e) {
                    Assert.assertTrue(Chars.contains(e.getMessage(), "could not mmap"));
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 9 with SqlCompiler

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

the class SampleByTest method testGroupByFail.

@Test
public void testGroupByFail() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as " + "(" + "select" + " x," + " rnd_double(0) d," + " rnd_symbol('XY','ZP', null, 'UU') c" + " from" + " long_sequence(1000000)" + ")", sqlExecutionContext);
        engine.clear();
        final FilesFacade ff = new FilesFacadeImpl() {

            int count = 10;

            @Override
            public long mmap(long fd, long len, long offset, int flags, int memoryTag) {
                if (count-- > 0) {
                    return super.mmap(fd, len, offset, flags, memoryTag);
                }
                return -1;
            }
        };
        final CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

            @Override
            public FilesFacade getFilesFacade() {
                return ff;
            }
        };
        try (CairoEngine engine = new CairoEngine(configuration)) {
            try (SqlCompiler compiler = new SqlCompiler(engine)) {
                try {
                    try (RecordCursorFactory factory = compiler.compile("select c, sum_t(d) from x", sqlExecutionContext).getRecordCursorFactory()) {
                        factory.getCursor(sqlExecutionContext);
                    }
                    Assert.fail();
                } catch (CairoException e) {
                    TestUtils.assertContains(e.getFlyweightMessage(), "could not mmap");
                }
                Assert.assertEquals(0, engine.getBusyReaderCount());
                Assert.assertEquals(0, engine.getBusyWriterCount());
            }
            engine.clear();
        }
    });
}
Also used : FilesFacade(io.questdb.std.FilesFacade) SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) FilesFacadeImpl(io.questdb.std.FilesFacadeImpl) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Example 10 with SqlCompiler

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

the class TextLoaderTest method assertTimestampAsLong.

private void assertTimestampAsLong(String nominatedTimestamp, String expectedMeta) throws Exception {
    final TextConfiguration textConfiguration = new DefaultTextConfiguration() {

        @Override
        public int getTextAnalysisMaxLines() {
            return 3;
        }
    };
    CairoConfiguration configuration = new DefaultCairoConfiguration(root) {

        @Override
        public TextConfiguration getTextConfiguration() {
            return textConfiguration;
        }
    };
    try (CairoEngine engine = new CairoEngine(configuration)) {
        try (SqlCompiler compiler = new SqlCompiler(engine)) {
            compiler.compile("create table test(StrSym symbol, ts timestamp) " + nominatedTimestamp, sqlExecutionContext);
            engine.releaseAllWriters();
        }
        assertNoLeak(engine, textLoader -> {
            String expected = "StrSym\tts\n" + "CMP1\t1970-04-26T17:46:40.000000Z\n" + "CMP2\t1970-04-26T17:46:40.000001Z\n" + "CMP1\t1970-04-26T17:46:40.000002Z\n" + "CMP2\t1970-04-26T17:46:40.000003Z\n" + "CMP1\t1970-04-26T17:46:40.000004Z\n";
            String csv = "StrSym,ts\n" + "CMP1,10000000000000\n" + "CMP2,10000000000001\n" + "CMP1,10000000000002\n" + "CMP2,10000000000003\n" + "CMP1,10000000000004\n";
            configureLoaderDefaults(textLoader, (byte) ',');
            textLoader.setForceHeaders(false);
            playText(engine, textLoader, csv, 1024, expected, expectedMeta, 5, 5);
        });
    }
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler)

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