Search in sources :

Example 16 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class MergingRowSourceTest method testMerge.

@Test
public void testMerge() throws JournalException, NumericException {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class)) {
        TestUtils.generateQuoteData(w, 100000, DateFormatUtils.parseDateTime("2014-02-11T00:00:00.000Z"), 10);
        RowSource srcA = new KvIndexSymLookupRowSource("sym", "BP.L", true);
        RowSource srcB = new KvIndexSymLookupRowSource("sym", "WTB.L", true);
        try (RecordSource rs = new JournalRecordSource(new JournalPartitionSource(w.getMetadata(), true), new MergingRowSource(srcA, srcB))) {
            long last = 0;
            RecordCursor c = rs.prepareCursor(getFactory());
            try {
                int ts = rs.getMetadata().getColumnIndex("timestamp");
                while (c.hasNext()) {
                    long r = c.next().getDate(ts);
                    Assert.assertTrue(r > last);
                    last = r;
                }
            } finally {
                c.releaseCursor();
            }
        }
    }
}
Also used : Quote(com.questdb.model.Quote) MergingRowSource(com.questdb.ql.latest.MergingRowSource) HeapMergingRowSource(com.questdb.ql.latest.HeapMergingRowSource) RecordCursor(com.questdb.common.RecordCursor) KvIndexSymLookupRowSource(com.questdb.ql.latest.KvIndexSymLookupRowSource) KvIndexSymLookupRowSource(com.questdb.ql.latest.KvIndexSymLookupRowSource) MergingRowSource(com.questdb.ql.latest.MergingRowSource) HeapMergingRowSource(com.questdb.ql.latest.HeapMergingRowSource) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 17 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class RecordListTest method writeAndReadRecords.

private <T> void writeAndReadRecords(JournalWriter<T> journal, int count, int pageSize, RecordGenerator<T> generator) throws IOException, JournalException, ParserException {
    try {
        for (int i = 0; i < count; i++) {
            journal.append(generator.generate(i));
        }
        journal.commit();
        try (RecordList records = new RecordList(journal.getMetadata(), pageSize)) {
            LongList offsets = new LongList();
            try (RecordSource rs = compiler.compile(getFactory(), journal.getLocation().getName())) {
                long o = -1;
                RecordCursor cursor = rs.prepareCursor(getFactory());
                try {
                    for (Record rec : cursor) {
                        offsets.add(o = records.append(rec, o));
                    }
                } finally {
                    cursor.releaseCursor();
                }
            }
            int i = 0;
            records.toTop();
            while (records.hasNext()) {
                generator.assertRecord(records.next(), i++);
            }
        }
    } finally {
        journal.close();
    }
}
Also used : RecordCursor(com.questdb.common.RecordCursor) Record(com.questdb.common.Record) LongList(com.questdb.std.LongList)

Example 18 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class GenericBinaryTest method readOutputStream.

private List<byte[]> readOutputStream() throws ParserException {
    List<byte[]> result = new ArrayList<>();
    try (RecordSource rs = compile("bintest")) {
        RecordCursor cursor = rs.prepareCursor(getFactory());
        try {
            for (Record e : cursor) {
                ByteArrayOutputStream o = new ByteArrayOutputStream();
                e.getBin(0, o);
                result.add(o.toByteArray());
            }
        } finally {
            cursor.releaseCursor();
        }
        return result;
    }
}
Also used : RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) ArrayList(java.util.ArrayList) Record(com.questdb.common.Record)

Example 19 with RecordCursor

use of com.questdb.common.RecordCursor in project questdb by bluestreak01.

the class GenericBinaryTest method testOutputInput.

@Test
public void testOutputInput() throws Exception {
    try (JournalWriter writer = getGenericWriter()) {
        List<byte[]> expected = getBytes();
        writeOutputStream(writer, expected);
        List<byte[]> actual = new ArrayList<>();
        try (RecordSource rs = compile("bintest")) {
            RecordCursor cursor = rs.prepareCursor(getFactory());
            try {
                for (Record e : cursor) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    InputStream in = e.getBin(0);
                    int b;
                    while ((b = in.read()) != -1) {
                        out.write(b);
                    }
                    actual.add(out.toByteArray());
                }
                assertEquals(expected, actual);
            } finally {
                cursor.releaseCursor();
            }
        }
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordSource(com.questdb.ql.RecordSource) RecordCursor(com.questdb.common.RecordCursor) ArrayList(java.util.ArrayList) Record(com.questdb.common.Record) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 20 with RecordCursor

use of com.questdb.common.RecordCursor 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)

Aggregations

RecordCursor (com.questdb.common.RecordCursor)26 Record (com.questdb.common.Record)19 Test (org.junit.Test)14 RecordSource (com.questdb.ql.RecordSource)11 AbstractTest (com.questdb.test.tools.AbstractTest)7 JournalWriter (com.questdb.store.JournalWriter)6 JournalEntryWriter (com.questdb.store.JournalEntryWriter)5 RecordSourcePrinter (com.questdb.ql.RecordSourcePrinter)3 Rnd (com.questdb.std.Rnd)3 StringSink (com.questdb.std.str.StringSink)3 EntryLockedException (com.questdb.cairo.pool.ex.EntryLockedException)2 EntryUnavailableException (com.questdb.cairo.pool.ex.EntryUnavailableException)2 PoolClosedException (com.questdb.cairo.pool.ex.PoolClosedException)2 SymbolTable (com.questdb.common.SymbolTable)2 Quote (com.questdb.model.Quote)2 AbstractOptimiserTest (com.questdb.parser.sql.AbstractOptimiserTest)2 HeapMergingRowSource (com.questdb.ql.latest.HeapMergingRowSource)2 KvIndexSymLookupRowSource (com.questdb.ql.latest.KvIndexSymLookupRowSource)2 MergingRowSource (com.questdb.ql.latest.MergingRowSource)2 RedBlackTree (com.questdb.std.RedBlackTree)2