Search in sources :

Example 11 with ObjList

use of com.questdb.std.ObjList in project questdb by bluestreak01.

the class IteratorTest method testMerge.

@Test
public void testMerge() throws Exception {
    populateQuotes();
    ObjList<Journal<Quote>> journals = new ObjList<Journal<Quote>>() {

        {
            add(getFactory().reader(Quote.class, "quote-0"));
            add(getFactory().reader(Quote.class, "quote-1"));
            add(getFactory().reader(Quote.class, "quote-2"));
            add(getFactory().reader(Quote.class, "quote-3"));
            add(getFactory().reader(Quote.class, "quote-4"));
        }
    };
    try {
        List<JournalIterator<Quote>> list = new ArrayList<>();
        for (int i = 0; i < journals.size(); i++) {
            list.add(JournalIterators.bufferedIterator(journals.get(i)));
        }
        long ts = 0;
        for (Quote q : MergingIterator.merge(list, comparator)) {
            Assert.assertTrue(ts <= q.getTimestamp());
            ts = q.getTimestamp();
        }
    } finally {
        for (int i = 0, n = journals.size(); i < n; i++) {
            journals.getQuick(i).close();
        }
    }
}
Also used : Quote(com.questdb.model.Quote) ObjList(com.questdb.std.ObjList) ArrayList(java.util.ArrayList) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 12 with ObjList

use of com.questdb.std.ObjList in project questdb by bluestreak01.

the class JournalIterators method createRanges.

private static <T> ObjList<JournalIteratorRange> createRanges(Journal<T> journal, long lo) {
    ObjList<JournalIteratorRange> ranges = new ObjList<>();
    int loPartitionID = Rows.toPartitionIndex(lo);
    long loLocalRowID = Rows.toLocalRowID(lo);
    try {
        int count = journal.getPartitionCount();
        for (int i = loPartitionID; i < count; i++) {
            long localRowID = 0;
            if (i == loPartitionID) {
                localRowID = loLocalRowID;
            }
            Partition<T> p = journal.getPartition(i, true);
            long size = p.size();
            if (size > 0) {
                ranges.add(new JournalIteratorRange(p.getPartitionIndex(), localRowID, size - 1));
            }
        }
        return ranges;
    } catch (JournalException e) {
        throw new JournalRuntimeException(e);
    }
}
Also used : ObjList(com.questdb.std.ObjList) JournalException(com.questdb.std.ex.JournalException) JournalRuntimeException(com.questdb.common.JournalRuntimeException)

Aggregations

ObjList (com.questdb.std.ObjList)12 Test (org.junit.Test)7 JournalRuntimeException (com.questdb.common.JournalRuntimeException)4 Rnd (com.questdb.std.Rnd)4 JournalException (com.questdb.std.ex.JournalException)4 AbstractTest (com.questdb.test.tools.AbstractTest)4 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)3 Quote (com.questdb.model.Quote)2 Path (com.questdb.std.str.Path)2 JournalEntryWriter (com.questdb.store.JournalEntryWriter)2 JournalWriter (com.questdb.store.JournalWriter)2 ArrayList (java.util.ArrayList)2 BootstrapEnv (com.questdb.BootstrapEnv)1 ServerConfiguration (com.questdb.ServerConfiguration)1 FactoryFullException (com.questdb.ex.FactoryFullException)1 DoubleRecordSourceColumn (com.questdb.ql.ops.col.DoubleRecordSourceColumn)1 DoubleConstant (com.questdb.ql.ops.constant.DoubleConstant)1 AddDoubleOperator (com.questdb.ql.ops.plus.AddDoubleOperator)1 SelectedColumnsRecordSource (com.questdb.ql.select.SelectedColumnsRecordSource)1 VirtualColumnRecordSource (com.questdb.ql.virtual.VirtualColumnRecordSource)1