Search in sources :

Example 6 with ObjList

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

the class IteratorTest method testMergePeeking.

@Test
public void testMergePeeking() 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<JournalPeekingIterator<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 : MergingPeekingIterator.mergePeek(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 7 with ObjList

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

the class SymbolMapTest method testLookupPerformance.

// @Test
// public void testLookupPerformanceOld() throws JournalException {
// int N = 100000000;
// int symbolCount = 1024;
// ObjList<String> symbols = new ObjList<>();
// MMappedSymbolTable tab = new MMappedSymbolTable(symbolCount, 256, 1, new File(configuration.getRoot().toString()), "x", JournalMode.APPEND, 0, 0, false, true);
// Rnd rnd = new Rnd();
// long prev = -1L;
// for (int i = 0; i < symbolCount; i++) {
// CharSequence cs = rnd.nextChars(10);
// long key = tab.put(cs);
// symbols.add(cs.toString());
// Assert.assertEquals(prev + 1, key);
// prev = key;
// }
// 
// long t = System.nanoTime();
// for (int i = 0; i < N; i++) {
// int key = rnd.nextPositiveInt() % symbolCount;
// Assert.assertEquals(key, tab.put(symbols.getQuick(key)));
// }
// System.out.println(System.nanoTime() - t);
// }
@Test
public void testLookupPerformance() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int N = 10000000;
        int symbolCount = 1024;
        ObjList<String> symbols = new ObjList<>();
        try (Path path = new Path().of(configuration.getRoot())) {
            create(path, "x", symbolCount, true);
            try (SymbolMapWriter writer = new SymbolMapWriter(configuration, path, "x", 0)) {
                Rnd rnd = new Rnd();
                long prev = -1L;
                for (int i = 0; i < symbolCount; i++) {
                    CharSequence cs = rnd.nextChars(10);
                    long key = writer.put(cs);
                    symbols.add(cs.toString());
                    Assert.assertEquals(prev + 1, key);
                    prev = key;
                }
                long t = System.nanoTime();
                for (int i = 0; i < N; i++) {
                    int key = rnd.nextPositiveInt() % symbolCount;
                    Assert.assertEquals(key, writer.put(symbols.getQuick(key)));
                }
                System.out.println("SymbolMapWriter lookup performance [10M <500ms]: " + (System.nanoTime() - t) / 1000000);
            }
        }
    });
}
Also used : Path(com.questdb.std.str.Path) ObjList(com.questdb.std.ObjList) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 8 with ObjList

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

the class ObjListTest method testAdd.

@Test
public void testAdd() {
    Rnd rnd = new Rnd();
    ObjList<String> list = new ObjList<>();
    for (int i = 0; i < 100; i++) {
        list.add(rnd.nextString(10));
    }
    Assert.assertEquals(100, list.size());
    rnd.reset();
    for (int i = 0; i < list.size(); i++) {
        Assert.assertEquals(rnd.nextString(10), list.getQuick(i));
    }
}
Also used : ObjList(com.questdb.std.ObjList) Rnd(com.questdb.std.Rnd) Test(org.junit.Test)

Example 9 with ObjList

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

the class CachingReaderFactoryTest method testGetReadersBeforeFailure.

@SuppressWarnings("InfiniteLoopStatement")
@Test
public void testGetReadersBeforeFailure() throws Exception {
    // create journal
    final JournalMetadata<?> m = new JournalStructure("x").$date("ts").$().build();
    ((WriterFactory) getFactory()).writer(m).close();
    try (final CachingReaderFactory rf = new CachingReaderFactory(factoryContainer.getConfiguration(), 1000, 2)) {
        ObjList<Journal> readers = new ObjList<>();
        try {
            do {
                readers.add(rf.reader(m));
            } while (true);
        } catch (FactoryFullException e) {
            Assert.assertEquals(rf.getMaxEntries(), readers.size());
        } finally {
            for (int i = 0, n = readers.size(); i < n; i++) {
                readers.getQuick(i).close();
            }
        }
    }
}
Also used : ObjList(com.questdb.std.ObjList) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Journal(com.questdb.store.Journal) FactoryFullException(com.questdb.ex.FactoryFullException) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 10 with ObjList

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

the class SymbolNullQueryTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    int tradeCount = 100;
    int quoteCount = 300;
    JournalWriter trades = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("trades").$int("quoteId").$sym("tag1").$double("amount").recordCountHint(tradeCount).$ts());
    JournalWriter quotes = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("quotes").$int("quoteId").$sym("tag").$double("rate").recordCountHint(quoteCount).$ts());
    int tsIncrementMax = 10000;
    long timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
    Rnd rnd = new Rnd();
    ObjList<String> tags = new ObjList<>();
    for (int i = 0; i < 500; i++) {
        tags.add(rnd.nextBoolean() ? rnd.nextString(rnd.nextInt() & 15) : null);
    }
    for (int i = 0; i < quoteCount; i++) {
        JournalEntryWriter w = quotes.entryWriter();
        w.putInt(0, i);
        w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
        w.putDouble(2, rnd.nextDouble());
        w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
        w.append();
    }
    quotes.commit();
    timestamp = DateFormatUtils.parseDateTime("2015-03-23T00:00:00.000Z");
    for (int i = 0; i < tradeCount; i++) {
        JournalEntryWriter w = trades.entryWriter();
        w.putInt(0, rnd.nextPositiveInt() % quoteCount);
        w.putSym(1, tags.getQuick(rnd.nextPositiveInt() % tags.size()));
        w.putDouble(2, rnd.nextDouble());
        w.putDate(3, timestamp += rnd.nextPositiveInt() % tsIncrementMax);
        w.append();
    }
    quotes.close();
    trades.close();
}
Also used : JournalWriter(com.questdb.store.JournalWriter) ObjList(com.questdb.std.ObjList) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

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