use of io.questdb.griffin.engine.groupby.vect.GroupByJob in project questdb by bluestreak01.
the class EmbeddedApiTest method testConcurrentSQLExec.
@Test
public void testConcurrentSQLExec() throws Exception {
final CairoConfiguration configuration = new DefaultCairoConfiguration(temp.getRoot().getAbsolutePath());
final Log log = LogFactory.getLog("testConcurrentSQLExec");
TestUtils.assertMemoryLeak(() -> {
WorkerPool workerPool = new WorkerPool(new WorkerPoolConfiguration() {
@Override
public int[] getWorkerAffinity() {
return new int[] { -1, -1 };
}
@Override
public int getWorkerCount() {
return 2;
}
@Override
public boolean haltOnError() {
return false;
}
});
Rnd rnd = new Rnd();
try (final CairoEngine engine = new CairoEngine(configuration)) {
workerPool.assign(new GroupByJob(engine.getMessageBus()));
workerPool.start(log);
try {
// number of cores is current thread + workers in the pool
final SqlExecutionContextImpl ctx = new SqlExecutionContextImpl(engine, 2);
try (SqlCompiler compiler = new SqlCompiler(engine)) {
compiler.compile("create table abc (g double, ts timestamp) timestamp(ts) partition by DAY", ctx);
long timestamp = 0;
try (TableWriter writer = engine.getWriter(ctx.getCairoSecurityContext(), "abc", "testing")) {
for (int i = 0; i < 10_000_000; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putDouble(0, rnd.nextDouble());
row.append();
timestamp += 1_000_000;
}
writer.commit();
}
try (RecordCursorFactory factory = compiler.compile("select sum(g) from abc", ctx).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(ctx)) {
final Record ignored = cursor.getRecord();
// noinspection StatementWithEmptyBody
while (cursor.hasNext()) {
// access 'record' instance for field values
}
}
}
}
} finally {
workerPool.halt();
}
}
});
}
use of io.questdb.griffin.engine.groupby.vect.GroupByJob in project questdb by bluestreak01.
the class SqlCodeGeneratorTest method testVectorSumAvgDoubleRndColumnWithNullsParallel.
@Test
public void testVectorSumAvgDoubleRndColumnWithNullsParallel() throws Exception {
final AtomicBoolean running = new AtomicBoolean(true);
final SOCountDownLatch haltLatch = new SOCountDownLatch(1);
final GroupByJob job = new GroupByJob(engine.getMessageBus());
new Thread(() -> {
while (running.get()) {
job.run(0);
}
haltLatch.countDown();
}).start();
try {
assertQuery("avg\tsum\n" + "0.50035043\t834470.437288\n", "select round(avg(c), 9) avg, round(sum(c), 6) sum from x", "create table x as (select rnd_int(0,100,2) a, rnd_double(2) b, rnd_double(2) c, rnd_int() d from long_sequence(2000000))", null, false, true, true);
} finally {
running.set(false);
haltLatch.await();
}
}
use of io.questdb.griffin.engine.groupby.vect.GroupByJob in project questdb by bluestreak01.
the class HttpServer method addDefaultEndpoints.
public static void addDefaultEndpoints(HttpServer server, HttpServerConfiguration configuration, CairoEngine cairoEngine, WorkerPool workerPool, HttpRequestProcessorBuilder jsonQueryProcessorBuilder, FunctionFactoryCache functionFactoryCache) {
server.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return jsonQueryProcessorBuilder.newInstance();
}
@Override
public String getUrl() {
return "/exec";
}
});
server.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new TextImportProcessor(cairoEngine);
}
@Override
public String getUrl() {
return "/imp";
}
});
server.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new TextQueryProcessor(configuration.getJsonQueryProcessorConfiguration(), cairoEngine, workerPool.getWorkerCount(), functionFactoryCache);
}
@Override
public String getUrl() {
return "/exp";
}
});
server.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new TableStatusCheckProcessor(cairoEngine, configuration.getJsonQueryProcessorConfiguration());
}
@Override
public String getUrl() {
return "/chk";
}
});
server.bind(new HttpRequestProcessorFactory() {
@Override
public HttpRequestProcessor newInstance() {
return new StaticContentProcessor(configuration);
}
@Override
public String getUrl() {
return HttpServerConfiguration.DEFAULT_PROCESSOR_URL;
}
});
// jobs that help parallel execution of queries
workerPool.assign(new ColumnIndexerJob(cairoEngine.getMessageBus()));
workerPool.assign(new GroupByJob(cairoEngine.getMessageBus()));
workerPool.assign(new LatestByAllIndexedJob(cairoEngine.getMessageBus()));
}
Aggregations