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);
}
}
}
});
}
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);
}
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);
}
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");
}
}
});
}
Aggregations