Search in sources :

Example 16 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class PerformanceTest method testAllBySymbolValueOverIntervalNew.

@SuppressWarnings("StatementWithEmptyBody")
@Test
public void testAllBySymbolValueOverIntervalNew() throws JournalException, ParserException, NumericException {
    try (JournalWriter<Quote> w = getFactory().writer(Quote.class, "quote", TEST_DATA_SIZE)) {
        TestUtils.generateQuoteData(w, TEST_DATA_SIZE, DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z"), 1000);
        w.commit();
    }
    QueryCompiler compiler = new QueryCompiler();
    Factory factory = getFactory();
    try (RecordSource src = compiler.compile(factory, "quote where timestamp = '2013-10-05T10:00:00.000Z;10d' and sym = 'LLOY.L'")) {
        int count = 1000;
        long t = 0;
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            RecordCursor c = src.prepareCursor(factory);
            try {
                for (; c.hasNext(); ) {
                    c.next();
                }
            } finally {
                c.releaseCursor();
            }
        }
        LOG.info().$("NEW journal.query().all().withKeys(\"LLOY.L\").slice(interval) (query only) latency: ").$((System.nanoTime() - t) / count / 1000).$("μs").$();
    }
}
Also used : Quote(com.questdb.model.Quote) RecordSource(com.questdb.ql.RecordSource) Factory(com.questdb.store.factory.Factory) LogFactory(com.questdb.log.LogFactory) ReaderFactory(com.questdb.store.factory.ReaderFactory) QueryCompiler(com.questdb.parser.sql.QueryCompiler) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 17 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class RenameJournalTest method testReleaseOfJournalInPool.

@Test
public void testReleaseOfJournalInPool() throws Exception {
    createX();
    Factory f = getFactory();
    assertJournal(f, "x");
    sink.clear();
    compiler.execute(f, "rename table x to y");
    assertJournal(f, "y");
    sink.clear();
    createX();
    assertJournal(f, "x");
}
Also used : Factory(com.questdb.store.factory.Factory) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 18 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class RenameJournalTest method testJournalAlreadyOpenButIdle.

@Test
@SuppressWarnings("unchecked")
public void testJournalAlreadyOpenButIdle() throws Exception {
    createX();
    Factory factory = getFactory();
    assertJournal(factory, "x");
    sink.clear();
    compiler.execute(factory, "rename table x to y");
    assertJournal(factory, "y");
    // make sure caching readerFactory doesn't return old journal
    try {
        factory.reader(new JournalKey("x"));
        Assert.fail();
    } catch (JournalException e) {
        Assert.assertEquals("Journal does not exist", e.getMessage());
    }
    // make sure compile doesn't pick up old journal
    try {
        compiler.compile(factory, "x");
        Assert.fail("still exists");
    } catch (ParserException e) {
        Assert.assertEquals(0, QueryError.getPosition());
        TestUtils.assertEquals("Journal does not exist", QueryError.getMessage());
    }
    sink.clear();
    createX();
    assertJournal(factory, "x");
}
Also used : ParserException(com.questdb.ex.ParserException) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalKey(com.questdb.store.JournalKey) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 19 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class JournalTest method testOpenJournalWithWrongPartitionType.

@Test
public void testOpenJournalWithWrongPartitionType() throws Exception {
    try (JournalWriter<Quote> w = getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.NONE))) {
        TestUtils.generateQuoteData(w, 1000);
    }
    try {
        getFactory().writer(new JournalKey<>(Quote.class, "quote", PartitionBy.MONTH));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
    try (Factory f2 = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class).$sym("mode");
        }
    }.build(factoryContainer.getConfiguration().getJournalBase()))) {
        f2.writer(new JournalKey<>(Quote.class, "quote"));
        Assert.fail("Exception expected");
    } catch (JournalException e) {
    // expect exception
    }
}
Also used : Quote(com.questdb.model.Quote) JournalException(com.questdb.std.ex.JournalException) Factory(com.questdb.store.factory.Factory) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 20 with Factory

use of com.questdb.store.factory.Factory in project questdb by bluestreak01.

the class AppendObjectPartitioned method main.

/**
 * Appends 1 million quotes into journal partitioned by day. Journal can only be partitioned on values of timestamp column.
 *
 * @param args factory directory
 * @throws JournalException in case of any problems with the journal.
 */
public static void main(String[] args) throws JournalException {
    if (args.length != 1) {
        System.out.println("Usage: " + AppendObjectPartitioned.class.getName() + " <path>");
        System.exit(1);
    }
    String journalLocation = args[0];
    try (Factory factory = new Factory(new JournalConfigurationBuilder() {

        {
            $(Quote.class, "quote-by-day").partitionBy(PartitionBy.DAY).$ts();
        }
    }.build(journalLocation), 1000, 1, 0)) {
        Files.delete(new File(factory.getConfiguration().getJournalBase(), "quote-by-day"));
        // you can change it in runtime and also, optionally put journal in alternative location
        try (JournalWriter<Quote> writer = factory.writer(Quote.class)) {
            final int count = 1000000;
            final String[] symbols = { "AGK.L", "BP.L", "TLW.L", "ABF.L", "LLOY.L", "BT-A.L", "WTB.L", "RRS.L", "ADM.L", "GKN.L", "HSBA.L" };
            final Rnd r = new Rnd();
            // reuse same same instance of Quote class to keep GC under control
            final Quote q = new Quote();
            long t = System.nanoTime();
            for (int i = 0; i < count; i++) {
                // prepare object for new set of data
                q.clear();
                // generate some data
                q.setSym(symbols[Math.abs(r.nextInt() % (symbols.length - 1))]);
                q.setAsk(Math.abs(r.nextDouble()));
                q.setBid(Math.abs(r.nextDouble()));
                q.setAskSize(Math.abs(r.nextInt() % 10000));
                q.setBidSize(Math.abs(r.nextInt() % 10000));
                q.setEx("LXE");
                q.setMode("Fast trading");
                q.setTimestamp(System.currentTimeMillis() + (i * 100));
                writer.append(q);
            }
            // commit is necessary
            writer.commit();
            System.out.println("Journal size: " + writer.size());
            System.out.println("Generated " + count + " objects in " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - t) + "ms.");
        }
    }
}
Also used : Quote(org.questdb.examples.support.Quote) Factory(com.questdb.store.factory.Factory) Rnd(com.questdb.std.Rnd) JournalConfigurationBuilder(com.questdb.store.factory.configuration.JournalConfigurationBuilder) File(java.io.File)

Aggregations

Factory (com.questdb.store.factory.Factory)27 JournalConfigurationBuilder (com.questdb.store.factory.configuration.JournalConfigurationBuilder)13 JournalConfiguration (com.questdb.store.factory.configuration.JournalConfiguration)11 Price (org.questdb.examples.support.Price)8 File (java.io.File)6 QueryCompiler (com.questdb.parser.sql.QueryCompiler)5 JournalWriter (com.questdb.store.JournalWriter)5 Quote (org.questdb.examples.support.Quote)5 LogFactory (com.questdb.log.LogFactory)4 JournalClient (com.questdb.net.ha.JournalClient)4 RecordSource (com.questdb.ql.RecordSource)4 Rnd (com.questdb.std.Rnd)4 JournalListener (com.questdb.store.JournalListener)4 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)4 AbstractTest (com.questdb.test.tools.AbstractTest)4 Test (org.junit.Test)4 JournalServer (com.questdb.net.ha.JournalServer)3 ClientConfig (com.questdb.net.ha.config.ClientConfig)3 JournalException (com.questdb.std.ex.JournalException)3 JournalEntryWriter (com.questdb.store.JournalEntryWriter)3