Search in sources :

Example 56 with JournalEntryWriter

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

the class GenericBinaryTest method writeInputStream.

private void writeInputStream(JournalWriter writer, List<byte[]> bytes) throws JournalException {
    JournalEntryWriter w;
    for (int i = 0; i < bytes.size(); i++) {
        w = writer.entryWriter();
        w.putBin(0, new ByteArrayInputStream(bytes.get(i)));
        w.append();
    }
    writer.commit();
}
Also used : JournalEntryWriter(com.questdb.store.JournalEntryWriter)

Example 57 with JournalEntryWriter

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

the class GenericInteropTest method testPartialObjectReader.

@Test
public void testPartialObjectReader() 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();
        writer.commit();
    }
    try (Journal<Partial> reader = getFactory().reader(Partial.class, "test")) {
        String expected = "Partial{sym='EURUSD', created=19999, bid=1.24, ask=1.25, bidSize=10000, askSize=12000}";
        StringBuilder builder = new StringBuilder();
        for (Partial p : JournalIterators.bufferedIterator(reader)) {
            builder.append(p);
        }
        TestUtils.assertEquals(expected, builder);
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 58 with JournalEntryWriter

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

the class GenericInteropTest method testGenericStructureMismatch.

@Test
public void testGenericStructureMismatch() 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();
        writer.commit();
        writer.close();
    }
    try {
        getFactory().writer(new JournalStructure("test") {

            {
                $str("sym");
                $date("created");
            }
        });
        Assert.fail("Expected exception");
    } catch (JournalMetadataException ignore) {
    // expected
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalMetadataException(com.questdb.ex.JournalMetadataException) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 59 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter 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 60 with JournalEntryWriter

use of com.questdb.store.JournalEntryWriter 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)

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