Search in sources :

Example 1 with SqlException

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

the class MatchStrBindVariableTest method testSimple.

@Test
public void testSimple() throws Exception {
    assertMemoryLeak(() -> {
        compiler.compile("create table x as (select rnd_str() s from long_sequence(100))", sqlExecutionContext);
        try (RecordCursorFactory factory = compiler.compile("x where s ~ $1", sqlExecutionContext).getRecordCursorFactory()) {
            bindVariableService.setStr(0, "GQO");
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, TestUtils.printer);
            }
            TestUtils.assertEquals("s\n" + "YCTGQO\n", sink);
            bindVariableService.setStr(0, "QTQ");
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                TestUtils.printCursor(cursor, factory.getMetadata(), true, sink, TestUtils.printer);
            }
            TestUtils.assertEquals("s\n" + "ZWEVQTQO\n", sink);
            bindVariableService.setStr(0, null);
            try {
                factory.getCursor(sqlExecutionContext);
                Assert.fail();
            } catch (SqlException e) {
                Assert.assertEquals(12, e.getPosition());
                TestUtils.assertContains(e.getFlyweightMessage(), "NULL regex");
            }
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlException(io.questdb.griffin.SqlException) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Example 2 with SqlException

use of io.questdb.griffin.SqlException 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 3 with SqlException

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

the class EqGeoHashGeoHashFunctionFactoryTest method createEqFunctionAndAssert.

private void createEqFunctionAndAssert(boolean isConstant, boolean expectedEq) {
    try {
        Function func = factory.newInstance(-1, args, null, null, null);
        Assert.assertEquals(expectedEq, func.getBool(null));
        Assert.assertEquals(isConstant, func.isConstant());
        if (func instanceof NegatableBooleanFunction) {
            try {
                NegatingFunctionFactory nf = new NegatingFunctionFactory("noteq", factory);
                func = nf.newInstance(-1, args, null, null, null);
                Assert.assertEquals(!expectedEq, func.getBool(null));
            } catch (SqlException e) {
                e.printStackTrace();
                Assert.fail();
            }
        }
    } catch (SqlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException)

Example 4 with SqlException

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

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

the class SampleByTest method testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable.

@Test
public void testSampleByNoFillNotKeyedAlignToCalendarTimezoneVariable() 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, 300000000) k" + " from" + " long_sequence(100)" + ") timestamp(k) partition by NONE", sqlExecutionContext);
        RecordCursorFactory factory = compiler.compile("select k, count() from x sample by 90m align to calendar time zone $1 with offset $2", sqlExecutionContext).getRecordCursorFactory();
        String expectedMoscow = "k\tcount\n" + "1970-01-02T22:45:00.000000Z\t3\n" + "1970-01-03T00:15:00.000000Z\t18\n" + "1970-01-03T01:45:00.000000Z\t18\n" + "1970-01-03T03:15:00.000000Z\t18\n" + "1970-01-03T04:45:00.000000Z\t18\n" + "1970-01-03T06:15:00.000000Z\t18\n" + "1970-01-03T07:45:00.000000Z\t7\n";
        String expectedPrague = "k\tcount\n" + "1970-01-02T23:10:00.000000Z\t8\n" + "1970-01-03T00:40:00.000000Z\t18\n" + "1970-01-03T02:10:00.000000Z\t18\n" + "1970-01-03T03:40:00.000000Z\t18\n" + "1970-01-03T05:10:00.000000Z\t18\n" + "1970-01-03T06:40:00.000000Z\t18\n" + "1970-01-03T08:10:00.000000Z\t2\n";
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Moscow");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            assertCursor(expectedMoscow, cursor, factory.getMetadata(), true);
        }
        // invalid timezone
        sqlExecutionContext.getBindVariableService().setStr(0, "Oopsie");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:15");
        try {
            factory.getCursor(sqlExecutionContext);
            Assert.fail();
        } catch (SqlException e) {
            Assert.assertEquals(67, e.getPosition());
            TestUtils.assertContains(e.getFlyweightMessage(), "invalid timezone: Oopsie");
        }
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
        sqlExecutionContext.getBindVariableService().setStr(1, "uggs");
        try {
            factory.getCursor(sqlExecutionContext);
            Assert.fail();
        } catch (SqlException e) {
            Assert.assertEquals(82, e.getPosition());
            TestUtils.assertContains(e.getFlyweightMessage(), "invalid offset: uggs");
        }
        sqlExecutionContext.getBindVariableService().setStr(0, "Europe/Prague");
        sqlExecutionContext.getBindVariableService().setStr(1, "00:10");
        try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
            assertCursor(expectedPrague, cursor, factory.getMetadata(), true);
        }
    });
}
Also used : RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) RecordCursor(io.questdb.cairo.sql.RecordCursor) SqlException(io.questdb.griffin.SqlException) Test(org.junit.Test) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest)

Aggregations

SqlException (io.questdb.griffin.SqlException)17 SqlCompiler (io.questdb.griffin.SqlCompiler)9 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)9 Test (org.junit.Test)9 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)7 CairoConfiguration (io.questdb.cairo.CairoConfiguration)5 Function (io.questdb.cairo.sql.Function)5 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)5 ColumnType (io.questdb.cairo.ColumnType)4 RecordCursor (io.questdb.cairo.sql.RecordCursor)4 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)4 FunctionFactory (io.questdb.griffin.FunctionFactory)4 Constants (io.questdb.griffin.engine.functions.constants.Constants)4 Record (io.questdb.cairo.sql.Record)3 io.questdb.std (io.questdb.std)3 ObjList (io.questdb.std.ObjList)3 ExpressionNode (io.questdb.griffin.model.ExpressionNode)2 QueryColumn (io.questdb.griffin.model.QueryColumn)2 Runner (org.openjdk.jmh.runner.Runner)2 Options (org.openjdk.jmh.runner.options.Options)2