use of com.questdb.store.JournalWriter 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.JournalWriter in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelectPartitionBy.
@Test
public void testCreateAsSelectPartitionBy() 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) partition by MONTH record hint 100")) {
JournalMetadata m = w.getMetadata();
Assert.assertEquals(11, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType());
Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType());
Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType());
Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType());
Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertEquals(8, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.MONTH, m.getPartitionBy());
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelectIndexes.
@Test
public void testCreateAsSelectIndexes() 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), index (a), index(x), index(z)")) {
JournalMetadata m = w.getMetadata();
Assert.assertEquals(11, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertTrue(m.getColumn("a").isIndexed());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType());
Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType());
Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType());
Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType());
Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertTrue(m.getColumn("x").isIndexed());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertTrue(m.getColumn("z").isIndexed());
Assert.assertEquals(8, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
use of com.questdb.store.JournalWriter in project questdb by bluestreak01.
the class DDLTests method testCreateAsSelect.
@Test
public void testCreateAsSelect() 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)")) {
JournalMetadata m = w.getMetadata();
Assert.assertEquals(11, m.getColumnCount());
Assert.assertEquals(ColumnType.INT, m.getColumn("a").getType());
Assert.assertEquals(ColumnType.BYTE, m.getColumn("b").getType());
Assert.assertEquals(ColumnType.SHORT, m.getColumn("c").getType());
Assert.assertEquals(ColumnType.LONG, m.getColumn("d").getType());
Assert.assertEquals(ColumnType.FLOAT, m.getColumn("e").getType());
Assert.assertEquals(ColumnType.DOUBLE, m.getColumn("f").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("g").getType());
Assert.assertEquals(ColumnType.BINARY, m.getColumn("h").getType());
Assert.assertEquals(ColumnType.DATE, m.getColumn("t").getType());
Assert.assertEquals(ColumnType.SYMBOL, m.getColumn("x").getType());
Assert.assertEquals(ColumnType.STRING, m.getColumn("z").getType());
Assert.assertEquals(8, m.getTimestampIndex());
Assert.assertEquals(PartitionBy.NONE, m.getPartitionBy());
}
}
use of com.questdb.store.JournalWriter 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();
}
}
Aggregations