Search in sources :

Example 6 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class HttpQueryTestBuilder method run.

public void run(CairoConfiguration configuration, HttpClientCode code) throws Exception {
    final int[] workerAffinity = new int[workerCount];
    Arrays.fill(workerAffinity, -1);
    assertMemoryLeak(() -> {
        final String baseDir = temp.getRoot().getAbsolutePath();
        final DefaultHttpServerConfiguration httpConfiguration = serverConfigBuilder.withBaseDir(baseDir).build();
        final WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {

            @Override
            public int[] getWorkerAffinity() {
                return workerAffinity;
            }

            @Override
            public int getWorkerCount() {
                return workerCount;
            }

            @Override
            public boolean haltOnError() {
                return false;
            }
        });
        if (workerCount > 1) {
            workerPool.assignCleaner(Path.CLEANER);
        }
        CairoConfiguration cairoConfiguration = configuration;
        if (cairoConfiguration == null) {
            cairoConfiguration = new DefaultCairoConfiguration(baseDir);
        }
        try (CairoEngine engine = new CairoEngine(cairoConfiguration);
            HttpServer httpServer = new HttpServer(httpConfiguration, workerPool, false)) {
            TelemetryJob telemetryJob = null;
            if (telemetry) {
                telemetryJob = new TelemetryJob(engine);
            }
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new StaticContentProcessor(httpConfiguration);
                }

                @Override
                public String getUrl() {
                    return HttpServerConfiguration.DEFAULT_PROCESSOR_URL;
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return textImportProcessor != null ? textImportProcessor.create(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount()) : new TextImportProcessor(engine);
                }

                @Override
                public String getUrl() {
                    return "/upload";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount(), Metrics.enabled());
                }

                @Override
                public String getUrl() {
                    return "/query";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new TextQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, workerPool.getWorkerCount());
                }

                @Override
                public String getUrl() {
                    return "/exp";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new TableStatusCheckProcessor(engine, httpConfiguration.getJsonQueryProcessorConfiguration());
                }

                @Override
                public String getUrl() {
                    return "/chk";
                }
            });
            httpServer.bind(new HttpRequestProcessorFactory() {

                @Override
                public HttpRequestProcessor newInstance() {
                    return new JsonQueryProcessor(httpConfiguration.getJsonQueryProcessorConfiguration(), engine, 1, Metrics.enabled());
                }

                @Override
                public String getUrl() {
                    return "/exec";
                }
            });
            QueryCache.configure(httpConfiguration);
            workerPool.start(LOG);
            try {
                code.run(engine);
            } finally {
                workerPool.halt();
                if (telemetryJob != null) {
                    Misc.free(telemetryJob);
                }
            }
        }
    });
}
Also used : TelemetryJob(io.questdb.TelemetryJob) WorkerPool(io.questdb.mp.WorkerPool) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration)

Example 7 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration 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 8 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration in project questdb by bluestreak01.

the class SecurityTest method setUpReadOnlyExecutionContext.

@BeforeClass
public static void setUpReadOnlyExecutionContext() {
    CairoConfiguration readOnlyConfiguration = new DefaultCairoConfiguration(root) {

        @Override
        public int getSqlMapPageSize() {
            return 64;
        }

        @Override
        public int getSqlMapMaxResizes() {
            return 2;
        }

        @Override
        public long getSqlSortKeyPageSize() {
            return 64;
        }

        @Override
        public int getSqlSortKeyMaxPages() {
            return 2;
        }

        @Override
        public int getSqlJoinMetadataPageSize() {
            return 64;
        }

        @Override
        public int getSqlJoinMetadataMaxResizes() {
            return 10;
        }

        @Override
        public long getSqlSortLightValuePageSize() {
            return 1024;
        }

        @Override
        public int getSqlSortLightValueMaxPages() {
            return 11;
        }
    };
    memoryRestrictedEngine = new CairoEngine(readOnlyConfiguration);
    SqlExecutionInterruptor dummyInterruptor = () -> {
        int nCalls = nCheckInterruptedCalls.incrementAndGet();
        int max = maxNCheckInterruptedCalls;
        if (nCalls > max) {
            throw CairoException.instance(0).put("Interrupting SQL processing, max calls is ").put(max);
        }
    };
    readOnlyExecutionContext = new SqlExecutionContextImpl(memoryRestrictedEngine, 1).with(new CairoSecurityContextImpl(false), bindVariableService, null, -1, dummyInterruptor);
    memoryRestrictedCompiler = new SqlCompiler(memoryRestrictedEngine);
}
Also used : CairoSecurityContextImpl(io.questdb.cairo.security.CairoSecurityContextImpl) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoEngine(io.questdb.cairo.CairoEngine) CairoConfiguration(io.questdb.cairo.CairoConfiguration) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) BeforeClass(org.junit.BeforeClass)

Example 9 with CairoConfiguration

use of io.questdb.cairo.CairoConfiguration 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

CairoConfiguration (io.questdb.cairo.CairoConfiguration)9 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)8 CairoEngine (io.questdb.cairo.CairoEngine)7 SqlCompiler (io.questdb.griffin.SqlCompiler)5 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)5 Test (org.junit.Test)4 TableWriter (io.questdb.cairo.TableWriter)3 SqlExecutionContext (io.questdb.griffin.SqlExecutionContext)3 WorkerPool (io.questdb.mp.WorkerPool)3 AbstractCairoTest (io.questdb.cairo.AbstractCairoTest)2 Record (io.questdb.cairo.sql.Record)2 RecordCursor (io.questdb.cairo.sql.RecordCursor)2 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)2 SqlException (io.questdb.griffin.SqlException)2 WorkerPoolConfiguration (io.questdb.mp.WorkerPoolConfiguration)2 LoopInterruptedCheck (de.invesdwin.util.concurrent.loop.LoopInterruptedCheck)1 Instant (de.invesdwin.util.time.Instant)1 FDate (de.invesdwin.util.time.date.FDate)1 TelemetryJob (io.questdb.TelemetryJob)1 WorkerPoolAwareConfiguration (io.questdb.WorkerPoolAwareConfiguration)1