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