Search in sources :

Example 1 with GroupByJob

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();
            }
        }
    });
}
Also used : SqlCompiler(io.questdb.griffin.SqlCompiler) RecordCursor(io.questdb.cairo.sql.RecordCursor) Log(io.questdb.log.Log) Rnd(io.questdb.std.Rnd) GroupByJob(io.questdb.griffin.engine.groupby.vect.GroupByJob) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) WorkerPool(io.questdb.mp.WorkerPool) TableWriter(io.questdb.cairo.TableWriter) RecordCursorFactory(io.questdb.cairo.sql.RecordCursorFactory) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) Record(io.questdb.cairo.sql.Record) CairoEngine(io.questdb.cairo.CairoEngine) DefaultCairoConfiguration(io.questdb.cairo.DefaultCairoConfiguration) CairoConfiguration(io.questdb.cairo.CairoConfiguration) WorkerPoolConfiguration(io.questdb.mp.WorkerPoolConfiguration) Test(org.junit.Test)

Example 2 with GroupByJob

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();
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GroupByJob(io.questdb.griffin.engine.groupby.vect.GroupByJob) SOCountDownLatch(io.questdb.mp.SOCountDownLatch) Test(org.junit.Test)

Example 3 with GroupByJob

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()));
}
Also used : GroupByJob(io.questdb.griffin.engine.groupby.vect.GroupByJob) LatestByAllIndexedJob(io.questdb.griffin.engine.table.LatestByAllIndexedJob) ColumnIndexerJob(io.questdb.cairo.ColumnIndexerJob)

Aggregations

GroupByJob (io.questdb.griffin.engine.groupby.vect.GroupByJob)3 Test (org.junit.Test)2 CairoConfiguration (io.questdb.cairo.CairoConfiguration)1 CairoEngine (io.questdb.cairo.CairoEngine)1 ColumnIndexerJob (io.questdb.cairo.ColumnIndexerJob)1 DefaultCairoConfiguration (io.questdb.cairo.DefaultCairoConfiguration)1 TableWriter (io.questdb.cairo.TableWriter)1 Record (io.questdb.cairo.sql.Record)1 RecordCursor (io.questdb.cairo.sql.RecordCursor)1 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)1 SqlCompiler (io.questdb.griffin.SqlCompiler)1 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)1 LatestByAllIndexedJob (io.questdb.griffin.engine.table.LatestByAllIndexedJob)1 Log (io.questdb.log.Log)1 SOCountDownLatch (io.questdb.mp.SOCountDownLatch)1 WorkerPool (io.questdb.mp.WorkerPool)1 WorkerPoolConfiguration (io.questdb.mp.WorkerPoolConfiguration)1 Rnd (io.questdb.std.Rnd)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1