use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.
the class DDLTests method testCast.
public void testCast(int from, int to) throws Exception {
int n = 100;
try (JournalWriter w1 = compiler.createWriter(getFactory(), "create table y (a " + ColumnType.nameOf(from) + ") record hint 100")) {
Rnd rnd = new Rnd();
for (int i = 0; i < n; i++) {
JournalEntryWriter ew = w1.entryWriter();
switch(from) {
case ColumnType.INT:
ew.putInt(0, rnd.nextInt());
break;
case ColumnType.LONG:
ew.putLong(0, rnd.nextLong());
break;
case ColumnType.DATE:
ew.putDate(0, rnd.nextLong());
break;
case ColumnType.BYTE:
ew.put(0, rnd.nextByte());
break;
case ColumnType.SHORT:
ew.putShort(0, rnd.nextShort());
break;
case ColumnType.FLOAT:
ew.putFloat(0, rnd.nextFloat());
break;
case ColumnType.DOUBLE:
ew.putDouble(0, rnd.nextDouble());
break;
case ColumnType.SYMBOL:
ew.putSym(0, rnd.nextChars(10));
break;
case ColumnType.STRING:
ew.putStr(0, rnd.nextChars(10));
break;
default:
break;
}
ew.append();
}
w1.commit();
}
exec("create table x as (y), cast(a as " + ColumnType.nameOf(to) + ") record hint 100");
try (RecordSource rs = compiler.compile(getFactory(), "x")) {
Rnd rnd = new Rnd();
Assert.assertEquals(to, rs.getMetadata().getColumnQuick(0).getType());
RecordCursor cursor = rs.prepareCursor(getFactory());
try {
while (cursor.hasNext()) {
switch(from) {
case ColumnType.INT:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals((short) rnd.nextInt(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals((long) rnd.nextInt(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals((byte) rnd.nextInt(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals((float) rnd.nextInt(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals((double) rnd.nextInt(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals((long) rnd.nextInt(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals(rnd.nextInt(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.LONG:
case ColumnType.DATE:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals((short) rnd.nextLong(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals(rnd.nextLong(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals((byte) rnd.nextLong(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals((float) rnd.nextLong(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals((double) rnd.nextLong(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals(rnd.nextLong(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals((int) rnd.nextLong(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.BYTE:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals((short) rnd.nextByte(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals((long) rnd.nextByte(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals(rnd.nextByte(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals((float) rnd.nextByte(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals((double) rnd.nextByte(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals((long) rnd.nextByte(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals((int) rnd.nextByte(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.SHORT:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals(rnd.nextShort(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals((long) rnd.nextShort(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals((byte) rnd.nextShort(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals((float) rnd.nextShort(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals((double) rnd.nextShort(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals((long) rnd.nextShort(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals((int) rnd.nextShort(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.FLOAT:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals((short) rnd.nextFloat(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals((byte) rnd.nextFloat(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals(rnd.nextFloat(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals((double) rnd.nextFloat(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals((long) rnd.nextFloat(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals((int) rnd.nextFloat(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.DOUBLE:
switch(to) {
case ColumnType.SHORT:
Assert.assertEquals((short) rnd.nextDouble(), cursor.next().getShort(0));
break;
case ColumnType.LONG:
Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getLong(0));
break;
case ColumnType.BYTE:
Assert.assertEquals((byte) rnd.nextDouble(), cursor.next().getByte(0));
break;
case ColumnType.FLOAT:
Assert.assertEquals((float) rnd.nextDouble(), cursor.next().getFloat(0), 0.000000001f);
break;
case ColumnType.DOUBLE:
Assert.assertEquals(rnd.nextDouble(), cursor.next().getDouble(0), 0.000000001);
break;
case ColumnType.DATE:
Assert.assertEquals((long) rnd.nextDouble(), cursor.next().getDate(0));
break;
case ColumnType.INT:
Assert.assertEquals((int) rnd.nextDouble(), cursor.next().getInt(0));
break;
default:
break;
}
break;
case ColumnType.STRING:
switch(to) {
case ColumnType.SYMBOL:
TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0));
break;
default:
TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0));
break;
}
break;
case ColumnType.SYMBOL:
switch(to) {
case ColumnType.STRING:
TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getFlyweightStr(0));
break;
default:
TestUtils.assertEquals(rnd.nextChars(10), cursor.next().getSym(0));
break;
}
break;
default:
break;
}
}
} finally {
cursor.releaseCursor();
}
}
}
use of com.questdb.store.JournalEntryWriter 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.store.JournalEntryWriter in project questdb by bluestreak01.
the class RenameJournalTest method create.
private void create(String name) throws JournalException, ParserException {
try (JournalWriter w = compiler.createWriter(getFactory(), "create table " + name + "(a int) record hint 100")) {
JournalEntryWriter ew = w.entryWriter();
ew.putInt(0, 999);
ew.append();
w.commit();
}
}
use of com.questdb.store.JournalEntryWriter 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.store.JournalEntryWriter in project questdb by bluestreak01.
the class GenericBinaryTest method testUnclosedOutputOutput.
@Test
public void testUnclosedOutputOutput() throws Exception {
try (JournalWriter writer = getGenericWriter()) {
List<byte[]> expected = getBytes();
for (int i = 0; i < expected.size(); i++) {
JournalEntryWriter w = writer.entryWriter();
w.putBin(0).write(expected.get(i));
w.append();
}
writer.commit();
assertEquals(expected, readOutputStream());
}
}
Aggregations