use of com.questdb.std.Rnd in project questdb by bluestreak01.
the class SingleJournalQueryTest method testSearchIndexedSymNull.
@Test
public void testSearchIndexedSymNull() throws Exception {
try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$sym("id").index().buckets(128).$double("x").$double("y").$ts())) {
Rnd rnd = new Rnd();
ObjHashSet<String> names = getNames(rnd, 128);
int mask = 127;
long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
for (int i = 0; i < 10000; i++) {
JournalEntryWriter ew = w.entryWriter();
if ((rnd.nextPositiveInt() % 10) == 0) {
ew.putNull(0);
} else {
ew.putSym(0, names.get(rnd.nextInt() & mask));
}
ew.putDouble(1, rnd.nextDouble());
ew.putDouble(2, rnd.nextDouble());
ew.putDate(3, t += 10);
ew.append();
}
w.commit();
}
assertNullSearch();
}
use of com.questdb.std.Rnd in project questdb by bluestreak01.
the class OperatorTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
// this does thread local allocations that
// should not be accounted for while
// measuring query allocations and de-allocations
FACTORY_CONTAINER.getFactory().getConfiguration().exists("");
try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("abc").$int("i").$double("d").$float("f").$byte("b").$long("l").$str("str").$bool("boo").$sym("sym").$short("sho").$date("date").$ts().$())) {
int n = 1000;
String[] sym = { "AX", "XX", "BZ", "KK" };
Rnd rnd = new Rnd();
long t = Dates.toMillis(2016, 5, 1, 10, 20);
long d = Dates.toMillis(2016, 5, 1, 10, 20);
for (int i = 0; i < n; i++) {
JournalEntryWriter ew = w.entryWriter(t += 60000);
ew.putInt(0, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.INT_NaN : rnd.nextInt());
ew.putDouble(1, (rnd.nextPositiveInt() & 15) == 0 ? Double.NaN : rnd.nextDouble());
ew.putFloat(2, (rnd.nextPositiveInt() & 15) == 0 ? Float.NaN : rnd.nextFloat());
ew.put(3, (byte) rnd.nextInt());
ew.putLong(4, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.LONG_NaN : rnd.nextLong());
ew.putStr(5, (rnd.nextPositiveInt() & 15) == 0 ? null : sym[rnd.nextPositiveInt() % sym.length]);
ew.putBool(6, rnd.nextBoolean());
ew.putSym(7, (rnd.nextPositiveInt() & 15) == 0 ? null : sym[rnd.nextPositiveInt() % sym.length]);
ew.putShort(8, (short) rnd.nextInt());
d += 45000;
ew.putDate(9, (rnd.nextPositiveInt() & 15) == 0 ? Numbers.LONG_NaN : d);
ew.append();
}
w.commit();
}
}
use of com.questdb.std.Rnd in project questdb by bluestreak01.
the class SymbolNullQueryTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
int tradeCount = 100;
int quoteCount = 300;
JournalWriter trades = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("trades").$int("quoteId").$sym("tag1").$double("amount").recordCountHint(tradeCount).$ts());
JournalWriter quotes = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("quotes").$int("quoteId").$sym("tag").$double("rate").recordCountHint(quoteCount).$ts());
int tsIncrementMax = 10000;
long timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
Rnd rnd = new Rnd();
ObjList<String> tags = new ObjList<>();
for (int i = 0; i < 500; i++) {
tags.add(rnd.nextBoolean() ? rnd.nextString(rnd.nextInt() & 15) : null);
}
for (int i = 0; i < quoteCount; i++) {
JournalEntryWriter w = quotes.entryWriter();
w.putInt(0, i);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.commit();
timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
for (int i = 0; i < tradeCount; i++) {
JournalEntryWriter w = trades.entryWriter();
w.putInt(0, rnd.nextPositiveInt() % quoteCount);
w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
w.putDouble(2, rnd.nextDouble());
w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
w.append();
}
quotes.close();
trades.close();
}
use of com.questdb.std.Rnd in project questdb by bluestreak01.
the class HashTest method testStringHash.
@Test
public void testStringHash() {
Rnd rnd = new Rnd();
IntHashSet hashes = new IntHashSet(100000);
final int LEN = 64;
long address = Unsafe.malloc(LEN);
for (int i = 0; i < 100000; i++) {
rnd.nextChars(address, LEN / 2);
hashes.add(Hash.hashMem(address, LEN));
}
Assert.assertTrue("Hash function distribution dropped", hashes.size() > 99990);
}
use of com.questdb.std.Rnd in project questdb by bluestreak01.
the class IntervalFrameCursorTest method testReload.
public void testReload(int partitionBy, long increment, LongList intervals, int rowCount, CharSequence expected1, CharSequence expected2) throws Exception {
TestUtils.assertMemoryLeak(() -> {
try (TableModel model = new TableModel(configuration, "x", partitionBy).col("a", ColumnType.SYMBOL).indexed(true, 4).col("b", ColumnType.SYMBOL).indexed(true, 4).timestamp()) {
CairoTestUtils.create(model);
}
final Rnd rnd = new Rnd();
long timestamp = DateFormatUtils.parseDateTime("1980-01-01T00:00:00.000Z");
try (CairoEngine engine = new Engine(configuration)) {
final TableReaderRecord record = new TableReaderRecord();
final IntervalFrameCursorFactory factory = new IntervalFrameCursorFactory(engine, "x", intervals);
try (DataFrameCursor cursor = factory.getCursor()) {
// assert that there is nothing to start with
record.of(cursor.getReader());
assertEquals("", record, cursor);
try (TableWriter writer = new TableWriter(configuration, "x")) {
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
assertEquals(expected1, record, cursor);
timestamp = Dates.addYear(timestamp, 3);
for (int i = 0; i < rowCount; i++) {
TableWriter.Row row = writer.newRow(timestamp);
row.putSym(0, rnd.nextChars(4));
row.putSym(1, rnd.nextChars(4));
row.append();
timestamp += increment;
}
writer.commit();
Assert.assertTrue(cursor.reload());
if (expected2 != null) {
assertEquals(expected2, record, cursor);
} else {
assertEquals(expected1, record, cursor);
}
Assert.assertFalse(cursor.reload());
}
}
}
});
}
Aggregations