Search in sources :

Example 11 with SqlExecutionContext

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

the class CaseFunctionFactory method newInstance.

@Override
public Function newInstance(int position, @Transient ObjList<Function> args, @Transient IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    int n = args.size();
    int returnType = -1;
    final ObjList<Function> vars = new ObjList<>(n);
    final ObjList<Function> argsToPoke = new ObjList<>(n);
    Function elseBranch;
    int elseBranchPosition;
    if (n % 2 == 1) {
        elseBranch = args.getQuick(n - 1);
        elseBranchPosition = argPositions.getQuick(n - 1);
        n--;
    } else {
        elseBranch = null;
        elseBranchPosition = 0;
    }
    // compute return type in this loop
    for (int i = 0; i < n; i += 2) {
        Function bool = args.getQuick(i);
        Function value = args.getQuick(i + 1);
        if (!ColumnType.isBoolean(bool.getType())) {
            throw SqlException.position(argPositions.getQuick(i)).put("BOOLEAN expected, found ").put(ColumnType.nameOf(bool.getType()));
        }
        returnType = CaseCommon.getCommonType(returnType, value.getType(), argPositions.getQuick(i + 1));
        vars.add(bool);
        vars.add(value);
        argsToPoke.add(bool);
        argsToPoke.add(value);
    }
    if (elseBranch != null) {
        returnType = CaseCommon.getCommonType(returnType, elseBranch.getType(), elseBranchPosition);
        argsToPoke.add(elseBranch);
    }
    // next calculate cast functions
    for (int i = 1; i < n; i += 2) {
        vars.setQuick(i, CaseCommon.getCastFunction(vars.getQuick(i), argPositions.getQuick(i), returnType, configuration, sqlExecutionContext));
    }
    if (elseBranch != null) {
        elseBranch = CaseCommon.getCastFunction(elseBranch, elseBranchPosition, returnType, configuration, sqlExecutionContext);
    }
    final int argsLen = vars.size();
    final Function elseB = elseBranch != null ? elseBranch : Constants.getNullConstant(returnType);
    final CaseFunctionPicker picker = record -> {
        for (int i = 0; i < argsLen; i += 2) {
            if (vars.getQuick(i).getBool(record)) {
                return vars.getQuick(i + 1);
            }
        }
        return elseB;
    };
    return CaseCommon.getCaseFunction(position, returnType, picker, argsToPoke);
}
Also used : ColumnType(io.questdb.cairo.ColumnType) ObjList(io.questdb.std.ObjList) Transient(io.questdb.std.Transient) Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException) IntList(io.questdb.std.IntList) CairoConfiguration(io.questdb.cairo.CairoConfiguration) Constants(io.questdb.griffin.engine.functions.constants.Constants) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) FunctionFactory(io.questdb.griffin.FunctionFactory) Function(io.questdb.cairo.sql.Function) ObjList(io.questdb.std.ObjList)

Example 12 with SqlExecutionContext

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

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