use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class SingleJournalQueryTest method testStrConcat.
@Test
public void testStrConcat() throws Exception {
try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$str("x").$str("y").$int("z").$ts())) {
Rnd rnd = new Rnd();
long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
for (int i = 0; i < 1000; i++) {
JournalEntryWriter ew = w.entryWriter();
ew.putStr(0, rnd.nextString(4));
ew.putStr(1, rnd.nextString(2));
ew.putInt(2, rnd.nextInt());
ew.putDate(3, t += 10);
ew.append();
}
w.commit();
}
final String expected = "CJOU-OU\n" + "CQJS-HG\n" + "CEJF-PB\n" + "CSJK-PY\n" + "CJHU-JY\n";
assertThat(expected, "select x + '-' + y from tab where x ~ '^C.*J+'");
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class AbstractAllTypeTest 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("xyz").$int("i").$str("str").$ts().$())) {
// 100;
int n = 100;
String[] sym = { "AX", "XX", "BZ", "KK" };
Rnd rnd = new Rnd();
long t = Dates.toMillis(2016, 5, 1, 10, 20);
for (int i = 0; i < n; i++) {
JournalEntryWriter ew = w.entryWriter(t += 60000);
ew.putInt(0, rnd.nextInt());
ew.putStr(1, sym[rnd.nextPositiveInt() % sym.length]);
ew.append();
}
w.commit();
}
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 = 20;
String[] sym = { "AX", "XX", "BZ", "KK" };
Rnd rnd = new Rnd();
long t = Dates.toMillis(2016, 5, 1, 10, 20);
for (int i = 0; i < n; i++) {
JournalEntryWriter ew = w.entryWriter(t += 60000);
ew.putInt(0, rnd.nextInt());
ew.putDouble(1, rnd.nextDouble());
ew.putFloat(2, rnd.nextFloat());
ew.put(3, (byte) rnd.nextInt());
ew.putLong(4, rnd.nextLong());
ew.putStr(5, sym[rnd.nextPositiveInt() % sym.length]);
ew.putBool(6, rnd.nextBoolean());
ew.putSym(7, sym[rnd.nextPositiveInt() % sym.length]);
ew.putShort(8, (short) rnd.nextInt());
ew.putDate(9, rnd.nextLong());
ew.append();
}
w.commit();
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class AsOfPartitionedJoinRecordSourceTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
FACTORY_CONTAINER.getFactory().getConfiguration().exists("");
int xcount = 100;
int ycount = 10;
try (JournalWriter xw = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("x").$ts().$sym("ccy").$double("rate").$double("amount").$str("trader").$sym("contra").$float("fl").$short("sh").$long("ln").$bool("b").recordCountHint(xcount).$())) {
try (JournalWriter yw = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("y").$ts().$sym("ccy").$double("amount").$str("trader").recordCountHint(ycount).$())) {
Rnd rnd = new Rnd();
String[] ccy = new String[3];
for (int i = 0; i < ccy.length; i++) {
ccy[i] = rnd.nextChars(6).toString();
}
long ts = DateFormatUtils.parseDateTime("2015-03-10T00:00:00.000Z");
for (int i = 0; i < xcount; i++) {
JournalEntryWriter w = xw.entryWriter();
w.putDate(0, ts += 10000);
w.putSym(1, ccy[rnd.nextPositiveInt() % ccy.length]);
w.putDouble(2, rnd.nextDouble());
w.putDouble(3, rnd.nextDouble());
if (rnd.nextBoolean()) {
w.putStr(4, rnd.nextChars(rnd.nextPositiveInt() % 128));
} else {
w.putNull(4);
}
w.putSym(5, ccy[rnd.nextPositiveInt() % ccy.length]);
w.putFloat(6, rnd.nextFloat());
w.putShort(7, (short) rnd.nextInt());
w.putLong(8, rnd.nextLong());
w.putBool(9, rnd.nextBoolean());
w.append();
}
xw.commit();
ts = DateFormatUtils.parseDateTime("2015-03-10T00:00:00.000Z");
for (int i = 0; i < ycount; i++) {
JournalEntryWriter w = yw.entryWriter();
w.putDate(0, ts += 60000);
w.putSym(1, ccy[rnd.nextPositiveInt() % ccy.length]);
w.putDouble(2, rnd.nextDouble());
if (rnd.nextBoolean()) {
w.putStr(3, rnd.nextChars(rnd.nextPositiveInt() % 128));
} else {
w.putNull(3);
}
w.append();
}
yw.commit();
try (JournalWriter jwa = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("a").$ts().$sym("ccy").$double("rate").$())) {
try (JournalWriter jwb = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("b").$ts().$sym("ccy").$double("amount").$())) {
JournalEntryWriter ewa;
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:30:00.000Z"));
ewa.putSym(1, "X");
ewa.putDouble(2, 0.538);
ewa.append();
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:35:00.000Z"));
ewa.putSym(1, "Y");
ewa.putDouble(2, 1.35);
ewa.append();
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:37:00.000Z"));
ewa.putSym(1, "Y");
ewa.putDouble(2, 1.41);
ewa.append();
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:39:00.000Z"));
ewa.putSym(1, "X");
ewa.putDouble(2, 0.601);
ewa.append();
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:40:00.000Z"));
ewa.putSym(1, "Y");
ewa.putDouble(2, 1.26);
ewa.append();
ewa = jwa.entryWriter();
ewa.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:43:00.000Z"));
ewa.putSym(1, "Y");
ewa.putDouble(2, 1.29);
ewa.append();
jwa.commit();
JournalEntryWriter ewb;
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:27:00.000Z"));
ewb.putSym(1, "X");
ewb.putDouble(2, 1100);
ewb.append();
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:28:00.000Z"));
ewb.putSym(1, "X");
ewb.putDouble(2, 1200);
ewb.append();
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:29:00.000Z"));
ewb.putSym(1, "X");
ewb.putDouble(2, 1500);
ewb.append();
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:34:50.000Z"));
ewb.putSym(1, "Y");
ewb.putDouble(2, 130);
ewb.append();
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:36:00.000Z"));
ewb.putSym(1, "Y");
ewb.putDouble(2, 150);
ewb.append();
ewb = jwb.entryWriter();
ewb.putDate(0, DateFormatUtils.parseDateTime("2014-03-12T10:41:00.000Z"));
ewb.putSym(1, "Y");
ewb.putDouble(2, 12000);
ewb.append();
jwb.commit();
}
}
}
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelectBin.
@Test
public void testCreateAsSelectBin() throws Exception {
int N = 10000;
int SZ = 4096;
ByteBuffer buf = ByteBuffer.allocateDirect(SZ);
try {
long addr = ByteBuffers.getAddress(buf);
try (JournalWriter w = compiler.createWriter(getFactory(), "create table x (a INT, b BINARY)")) {
Rnd rnd = new Rnd();
for (int i = 0; i < N; i++) {
long p = addr;
int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8;
for (int j = 0; j < n; j++) {
Unsafe.getUnsafe().putLong(p, rnd.nextLong());
p += 8;
}
buf.limit(n * 8);
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, i);
ew.putBin(1, buf);
ew.append();
buf.clear();
}
w.commit();
}
exec("create table y as (x)");
int count = 0;
try (RecordSource rs = compiler.compile(getFactory(), "y")) {
RecordCursor cursor = rs.prepareCursor(getFactory());
try {
Rnd rnd = new Rnd();
while (cursor.hasNext()) {
Record rec = cursor.next();
Assert.assertEquals(count, rec.getInt(0));
long len = rec.getBinLen(1);
DirectInputStream is = rec.getBin(1);
is.copyTo(addr, 0, len);
long p = addr;
int n = (rnd.nextPositiveInt() % (SZ - 1)) / 8;
for (int j = 0; j < n; j++) {
Assert.assertEquals(rnd.nextLong(), Unsafe.getUnsafe().getLong(p));
p += 8;
}
count++;
}
} finally {
cursor.releaseCursor();
}
}
Assert.assertEquals(N, count);
} finally {
ByteBuffers.release(buf);
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelectSymbolCount.
@Test
public void testCreateAsSelectSymbolCount() throws Exception {
exec("create table y (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING) timestamp(t) partition by YEAR record hint 100");
try (JournalWriter w = compiler.createWriter(getFactory(), "create table x as (y order by t), cast(x as SYMBOL count 33), cast(b as INT)")) {
Assert.assertEquals(ColumnType.SYMBOL, w.getMetadata().getColumn("x").getType());
Assert.assertEquals(63, w.getMetadata().getColumn("x").getBucketCount());
}
}
Aggregations