Search in sources :

Example 81 with JournalWriter

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

the class GenericInteropTest method testGenericAll.

@Test
public void testGenericAll() throws Exception {
    try (JournalWriter writer = makeGenericWriter()) {
        JournalEntryWriter w = writer.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 19999);
        w.putDouble(2, 1.24);
        w.putDouble(3, 1.25);
        w.putInt(4, 10000);
        w.putInt(5, 12000);
        w.putInt(6, 1);
        w.putStr(7, "OK");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, true);
        w.putNull(11);
        w.putLong(12, 13141516);
        w.putShort(13, (short) 25000);
        w.append();
        w = writer.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 20000);
        w.putDouble(2, 1.23);
        w.putDouble(3, 1.26);
        w.putInt(4, 11000);
        w.putInt(5, 13000);
        w.putInt(6, 2);
        w.putStr(7, "STALE");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, false);
        w.putNull(11);
        w.putLong(12, 23242526);
        w.putShort(13, (short) 30000);
        w.append();
        writer.commit();
    }
    try (RecordSource rs = compile("test")) {
        RecordCursor cursor = rs.prepareCursor(getFactory());
        try {
            Record e;
            Assert.assertTrue(cursor.hasNext());
            Assert.assertNotNull(e = cursor.next());
            Assert.assertEquals("EURUSD", e.getSym(0));
            Assert.assertEquals(19999, e.getDate(1));
            Assert.assertEquals(1.24, e.getDouble(2), 0.000001);
            Assert.assertEquals(1.25, e.getDouble(3), 0.000001);
            Assert.assertEquals(10000, e.getInt(4));
            Assert.assertEquals(12000, e.getInt(5));
            Assert.assertEquals(1, e.getByte(6));
            TestUtils.assertEquals("OK", e.getFlyweightStr(7));
            TestUtils.assertEquals("system", e.getFlyweightStr(8));
            TestUtils.assertEquals("EURUSD:GLOBAL", e.getFlyweightStr(9));
            Assert.assertTrue(e.getBool(10));
            Assert.assertNull(e.getFlyweightStr(11));
            Assert.assertEquals(13141516, e.getLong(12));
            Assert.assertEquals(25000, e.getShort(13));
            Assert.assertTrue(cursor.hasNext());
            Assert.assertNotNull(e = cursor.next());
            Assert.assertEquals("EURUSD", e.getSym(0));
            Assert.assertEquals(20000, e.getDate(1));
            Assert.assertEquals(1.23, e.getDouble(2), 0.000001);
            Assert.assertEquals(1.26, e.getDouble(3), 0.000001);
            Assert.assertEquals(11000, e.getInt(4));
            Assert.assertEquals(13000, e.getInt(5));
            Assert.assertEquals(2, e.getByte(6));
            TestUtils.assertEquals("STALE", e.getFlyweightStr(7));
            TestUtils.assertEquals("system", e.getFlyweightStr(8));
            TestUtils.assertEquals("EURUSD:GLOBAL", e.getFlyweightStr(9));
            Assert.assertFalse(e.getBool(10));
            Assert.assertNull(e.getFlyweightStr(11));
            Assert.assertEquals(23242526, e.getLong(12));
            Assert.assertEquals(30000, e.getShort(13));
            Assert.assertFalse(cursor.hasNext());
        } finally {
            cursor.releaseCursor();
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 82 with JournalWriter

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

the class GenericInteropTest method testGenericWriteObjectRead.

@Test
public void testGenericWriteObjectRead() throws Exception {
    try (JournalWriter writer = makeGenericWriter()) {
        JournalEntryWriter w = writer.entryWriter();
        w.putSym(0, "EURUSD");
        w.putDate(1, 19999);
        w.putDouble(2, 1.24);
        w.putDouble(3, 1.25);
        w.putInt(4, 10000);
        w.putInt(5, 12000);
        w.putInt(6, 1);
        w.putStr(7, "OK");
        w.putStr(8, "system");
        w.putStr(9, "EURUSD:GLOBAL");
        w.putBool(10, true);
        w.putNull(11);
        w.putLong(12, 1234567);
        w.putShort(13, (short) 11000);
        w.append();
        writer.commit();
    }
    try (Journal<Data> reader = getFactory().reader(Data.class, "test")) {
        Iterator<Data> src = JournalIterators.bufferedIterator(reader);
        Assert.assertTrue(src.hasNext());
        Data d;
        Assert.assertNotNull(d = src.next());
        Assert.assertEquals("EURUSD", d.sym);
        Assert.assertEquals(19999, d.created);
        Assert.assertEquals(1.24, d.bid, 0.000001);
        Assert.assertEquals(1.25, d.ask, 0.000001);
        Assert.assertEquals(10000, d.bidSize);
        Assert.assertEquals(12000, d.askSize);
        Assert.assertEquals(1, d.id);
        Assert.assertEquals("OK", d.status);
        Assert.assertEquals("system", d.user);
        Assert.assertEquals("EURUSD:GLOBAL", d.rateId);
        Assert.assertTrue(d.active);
        Assert.assertNull(d.nullable);
        Assert.assertEquals(1234567, d.ticks);
        Assert.assertEquals(11000, d.modulo);
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 83 with JournalWriter

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

the class ComparatorCompilerTest method testAllGetters.

@Test
public void testAllGetters() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$bool("bool").$byte("byte").$double("double").$float("float").$int("int").$long("long").$date("date").$short("short").$str("str").$sym("sym").$())) {
        JournalEntryWriter ew = w.entryWriter();
        ew.putBool(0, true);
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "questdb");
        ew.append();
        ew = w.entryWriter();
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "appsicle");
        ew.append();
        w.commit();
        IntList indices = new IntList();
        for (int i = 0, n = w.getMetadata().getColumnCount(); i < n; i++) {
            indices.add(i + 1);
        }
        RecordSource rs = compileSource("xyz");
        RecordComparator rc = cc.compile(rs.getMetadata(), indices);
        RBTreeSortedRecordSource map = new RBTreeSortedRecordSource(rs, rc, 1024 * 1024, 4 * 1024 * 1024);
        sink.clear();
        printer.print(map, FACTORY_CONTAINER.getFactory());
    }
    TestUtils.assertEquals("false\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tappsicle\n" + "true\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tquestdb\n", sink);
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordSource(com.questdb.ql.RecordSource) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalEntryWriter(com.questdb.store.JournalEntryWriter) IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 84 with JournalWriter

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

the class RBTreeSortedRecordSourceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$int("i").$str("str").$())) {
        int n = 100;
        Rnd rnd = new Rnd();
        for (int i = 0; i < n; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, rnd.nextInt());
            ew.putStr(1, rnd.nextChars(2));
            ew.append();
        }
        w.commit();
    }
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("dupes").$int("x").$())) {
        for (int i = 0; i < 10; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, i % 2 == 0 ? 10 : 20);
            ew.append();
        }
        JournalEntryWriter ew = w.entryWriter();
        ew.putInt(0, 30);
        ew.append();
        w.commit();
    }
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("timeseries").$double("d").$ts().$())) {
        Rnd rnd = new Rnd();
        long ts = Dates.toMillis(2016, 3, 12, 0, 0);
        for (int i = 0; i < 1000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putDouble(0, rnd.nextDouble());
            ew.putDate(1, ts + (rnd.nextPositiveInt() % Dates.DAY_MILLIS));
            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 85 with JournalWriter

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

the class $TabsRecordSourceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    try (JournalWriter w = compiler.createWriter(FACTORY_CONTAINER.getFactory(), "create table xyz(x int, y string, timestamp date) timestamp(timestamp) partition by MONTH")) {
        JournalEntryWriter ew;
        ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-01-02T00:00:00.000Z"));
        ew.putInt(0, 0);
        ew.append();
        ew = w.entryWriter(DateFormatUtils.parseDateTime("2016-02-02T00:00:00.000Z"));
        ew.putInt(0, 1);
        ew.append();
        w.commit();
    }
    $TabsRecordSource.init();
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

JournalWriter (com.questdb.store.JournalWriter)93 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)59 AbstractTest (com.questdb.test.tools.AbstractTest)54 Test (org.junit.Test)52 Rnd (com.questdb.std.Rnd)42 BeforeClass (org.junit.BeforeClass)12 CountDownLatch (java.util.concurrent.CountDownLatch)9 RecordCursor (com.questdb.common.RecordCursor)6 JournalException (com.questdb.std.ex.JournalException)6 Record (com.questdb.common.Record)5 RecordSource (com.questdb.ql.RecordSource)5 Factory (com.questdb.store.factory.Factory)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)4 ServerConfig (com.questdb.net.ha.config.ServerConfig)4 ServerNode (com.questdb.net.ha.config.ServerNode)4 StringSink (com.questdb.std.str.StringSink)4