Search in sources :

Example 26 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter 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();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Example 27 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter 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();
                }
            }
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Example 28 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter 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);
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record) ByteBuffer(java.nio.ByteBuffer) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 29 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class DDLTests method testCreateAsSelectAll.

@Test
public void testCreateAsSelectAll() throws Exception {
    int N = 50;
    try (JournalWriter w = compiler.createWriter(getFactory(), "create table x (a INT, b BYTE, c SHORT, d LONG, e FLOAT, f DOUBLE, g DATE, h BINARY, t DATE, x SYMBOL, z STRING, y BOOLEAN) timestamp(t) record hint 100")) {
        Rnd rnd = new Rnd();
        long t = DateFormatUtils.parseDateTime("2016-01-10T00:00:00.000Z");
        for (int i = 0; i < N; i++) {
            JournalEntryWriter ew = w.entryWriter(t += Dates.DAY_MILLIS);
            ew.putInt(0, i);
            ew.put(1, (byte) rnd.nextInt());
            ew.putShort(2, (short) rnd.nextInt());
            ew.putLong(3, rnd.nextLong());
            ew.putFloat(4, rnd.nextFloat());
            ew.putDouble(5, rnd.nextDouble());
            ew.putDate(6, rnd.nextLong());
            ew.putNull(7);
            ew.putSym(9, rnd.nextChars(1));
            ew.putStr(10, rnd.nextChars(10));
            ew.putBool(11, rnd.nextBoolean());
            ew.append();
        }
        w.commit();
    }
    exec("create table y as (x) partition by MONTH");
    try (Journal r = getFactory().reader("y")) {
        Assert.assertEquals(2, r.getPartitionCount());
    }
    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));
                Assert.assertTrue((byte) rnd.nextInt() == rec.getByte(1));
                Assert.assertEquals((short) rnd.nextInt(), rec.getShort(2));
                Assert.assertEquals(rnd.nextLong(), rec.getLong(3));
                Assert.assertEquals(rnd.nextFloat(), rec.getFloat(4), 0.00001f);
                Assert.assertEquals(rnd.nextDouble(), rec.getDouble(5), 0.00000000001);
                Assert.assertEquals(rnd.nextLong(), rec.getDate(6));
                Assert.assertNull(rec.getBin(7));
                TestUtils.assertEquals(rnd.nextChars(1), rec.getSym(9));
                TestUtils.assertEquals(rnd.nextChars(10), rec.getFlyweightStr(10));
                Assert.assertEquals(rnd.nextBoolean(), rec.getBool(11));
                count++;
            }
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordCursor(com.questdb.common.RecordCursor) Journal(com.questdb.store.Journal) Record(com.questdb.common.Record) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 30 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter in project questdb by bluestreak01.

the class JournalRecordSourceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("parent").$int("i").$double("d").$float("f").$byte("b").$long("l").$str("str").$bool("boo").$sym("sym").$short("sho").$date("date").$ts().partitionBy(PartitionBy.DAY).$())) {
        Rnd rnd = new Rnd();
        // number of records
        int n = 24 * 3;
        // time stepping 1hr
        int timestep = 60 * 60 * 1000;
        String[] sym = { "AX", "XX", "BZ", "KK", "PP", "UX", "LK" };
        String[] str = new String[16];
        for (int i = 0; i < str.length; i++) {
            str[i] = rnd.nextString(rnd.nextPositiveInt() % 10);
        }
        long t = Dates.toMillis(2016, 5, 1, 10, 20);
        for (int i = 0; i < n; i++) {
            JournalEntryWriter ew = w.entryWriter(t += timestep);
            ew.putInt(0, rnd.nextInt() % 15);
            ew.putDouble(1, rnd.nextDouble());
            ew.putFloat(2, rnd.nextFloat());
            ew.put(3, (byte) rnd.nextInt());
            ew.putLong(4, rnd.nextLong() % 30);
            ew.putStr(5, str[rnd.nextPositiveInt() % str.length]);
            ew.putBool(6, rnd.nextBoolean());
            ew.putSym(7, sym[rnd.nextPositiveInt() % sym.length]);
            ew.putShort(8, (short) (rnd.nextInt() % 20));
            ew.putDate(9, rnd.nextLong());
            ew.append();
        }
        w.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

JournalEntryWriter (com.questdb.store.JournalEntryWriter)67 JournalWriter (com.questdb.store.JournalWriter)59 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)31 AbstractTest (com.questdb.test.tools.AbstractTest)28 BeforeClass (org.junit.BeforeClass)10 RecordCursor (com.questdb.common.RecordCursor)5 Record (com.questdb.common.Record)4 RecordSource (com.questdb.ql.RecordSource)4 StringSink (com.questdb.std.str.StringSink)4 BootstrapEnv (com.questdb.BootstrapEnv)3 ServerConfiguration (com.questdb.ServerConfiguration)3 ObjHashSet (com.questdb.std.ObjHashSet)3 Factory (com.questdb.store.factory.Factory)3 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 DoubleRecordSourceColumn (com.questdb.ql.ops.col.DoubleRecordSourceColumn)2 DoubleConstant (com.questdb.ql.ops.constant.DoubleConstant)2 AddDoubleOperator (com.questdb.ql.ops.plus.AddDoubleOperator)2 VirtualColumnRecordSource (com.questdb.ql.virtual.VirtualColumnRecordSource)2