Search in sources :

Example 11 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class LongTreeSetTest method doTestSimple.

private void doTestSimple(LongTreeSet set) {
    Rnd rnd = new Rnd();
    LongList ll = new LongList();
    int n = 10000;
    for (int i = 0; i < n; i++) {
        long l = rnd.nextLong();
        set.put(l);
        ll.add(l);
    }
    ll.sort();
    int i = 0;
    LongTreeSet.TreeCursor cursor = set.getCursor();
    while (cursor.hasNext()) {
        long l = cursor.next();
        Assert.assertEquals(ll.getQuick(i++), l);
    }
    Assert.assertEquals(n, i);
    cursor.toTop();
    i = 0;
    while (cursor.hasNext()) {
        long l = cursor.next();
        Assert.assertEquals(ll.getQuick(i++), l);
    }
}
Also used : LongTreeSet(io.questdb.griffin.engine.table.LongTreeSet) Rnd(io.questdb.std.Rnd) LongList(io.questdb.std.LongList)

Example 12 with Rnd

use of io.questdb.std.Rnd 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 13 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class InsertTest method testGeoHash.

@Test
public void testGeoHash() throws Exception {
    final TimestampFunction timestampFunction = new TimestampFunction() {

        private long last = TimestampFormatUtils.parseTimestamp("2019-03-10T00:00:00.000000Z");

        @Override
        public long getTimestamp() {
            return last = last + 100000L * 30 * 12;
        }
    };
    assertMemoryLeak(() -> {
        try (TableModel model = CairoTestUtils.getGeoHashTypesModelWithNewTypes(configuration, PartitionBy.YEAR)) {
            CairoTestUtils.createTable(model);
        }
        Rnd rnd = new Rnd();
        final String sql;
        sql = "insert into allgeo values (" + "$1, " + "$2, " + "$3, " + "$4, " + "$5)";
        final CompiledQuery cq = compiler.compile(sql, sqlExecutionContext);
        Assert.assertEquals(CompiledQuery.INSERT, cq.getType());
        InsertStatement insert = cq.getInsertStatement();
        try (InsertMethod method = insert.createMethod(sqlExecutionContext)) {
            for (int i = 0; i < 10_000; i++) {
                bindVariableService.setGeoHash(0, rnd.nextGeoHashByte(6), ColumnType.getGeoHashTypeWithBits(6));
                bindVariableService.setGeoHash(1, rnd.nextGeoHashShort(12), ColumnType.getGeoHashTypeWithBits(12));
                // truncate this one, target column is 27 bit
                bindVariableService.setGeoHash(2, rnd.nextGeoHashInt(29), ColumnType.getGeoHashTypeWithBits(29));
                bindVariableService.setGeoHash(3, rnd.nextGeoHashLong(44), ColumnType.getGeoHashTypeWithBits(44));
                bindVariableService.setTimestamp(4, timestampFunction.getTimestamp());
                method.execute();
            }
            method.commit();
        }
        rnd.reset();
        try (TableReader reader = engine.getReader(sqlExecutionContext.getCairoSecurityContext(), "allgeo")) {
            final TableReaderRecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            while (cursor.hasNext()) {
                Assert.assertEquals(rnd.nextGeoHashByte(6), record.getGeoByte(0));
                Assert.assertEquals(rnd.nextGeoHashShort(12), record.getGeoShort(1));
                Assert.assertEquals(ColumnType.truncateGeoHashBits(rnd.nextGeoHashInt(29), 29, 27), record.getGeoInt(2));
                Assert.assertEquals(rnd.nextGeoHashLong(44), record.getGeoLong(3));
            }
        }
    });
}
Also used : Rnd(io.questdb.std.Rnd) Test(org.junit.Test)

Example 14 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class ReplModelReconTest method setUp.

@Override
public void setUp() {
    super.setUp();
    CairoConfiguration.RANDOM.set(new Rnd());
}
Also used : Rnd(io.questdb.std.Rnd)

Example 15 with Rnd

use of io.questdb.std.Rnd in project questdb by bluestreak01.

the class CharGroupByFunctionTest method testNonNull.

@Test
public void testNonNull() throws SqlException {
    sqlExecutionContext.setRandom(new Rnd());
    compiler.compile("create table tab as ( select rnd_char() ch from long_sequence(100) )", sqlExecutionContext);
    assertSql("select min(ch) from tab", "min\n" + "B\n");
    assertSql("select max(ch) from tab", "max\n" + "Z\n");
    assertSql("select first(ch) from tab", "first\n" + "V\n");
    assertSql("select last(ch) from tab", "last\n" + "J\n");
}
Also used : Rnd(io.questdb.std.Rnd) AbstractGriffinTest(io.questdb.griffin.AbstractGriffinTest) Test(org.junit.Test)

Aggregations

Rnd (io.questdb.std.Rnd)76 Test (org.junit.Test)49 Record (io.questdb.cairo.sql.Record)32 RecordCursor (io.questdb.cairo.sql.RecordCursor)29 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)28 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)24 TableWriter (io.questdb.cairo.TableWriter)23 Path (io.questdb.std.str.Path)10 RuntimeIntervalModel (io.questdb.griffin.model.RuntimeIntervalModel)4 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)2 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)2 RowCursor (io.questdb.cairo.sql.RowCursor)2 StaticSymbolTable (io.questdb.cairo.sql.StaticSymbolTable)2 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)2 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)2 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)2 BinarySequence (io.questdb.std.BinarySequence)2 BytecodeAssembler (io.questdb.std.BytecodeAssembler)2 FilesFacade (io.questdb.std.FilesFacade)2