Search in sources :

Example 56 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure 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)

Example 57 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class GenericInteropTest method testInvalidColumnName.

@Test
public void testInvalidColumnName() throws Exception {
    File location = null;
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status?\0x");
        }
    })) {
        location = w.getLocation();
        w.entryWriter();
    } catch (JournalException ignore) {
    // ignore
    }
    Assert.assertNotNull(location);
    Files.deleteOrException(location);
    try (JournalWriter w = getFactory().writer(new JournalStructure("test") {

        {
            $int("id").index();
            $str("status");
        }
    })) {
        w.entryWriter();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalException(com.questdb.std.ex.JournalException) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) File(java.io.File) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 58 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure 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 JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class ComparatorCompilerTest method testAllGetters.

@Test
public void testAllGetters() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$bool("bool").$byte("byte").$double("double").$float("float").$int("int").$long("long").$date("date").$short("short").$str("str").$sym("sym").$())) {
        JournalEntryWriter ew = w.entryWriter();
        ew.putBool(0, true);
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "questdb");
        ew.append();
        ew = w.entryWriter();
        ew.put(1, (byte) 13);
        ew.putDouble(2, 20.12);
        ew.putFloat(3, 10.15f);
        ew.putInt(4, 4);
        ew.putLong(5, 9988908080988890L);
        ew.putDate(6, 88979879L);
        ew.putShort(7, (short) 902);
        ew.putStr(8, "complexity made simple");
        ew.putSym(9, "appsicle");
        ew.append();
        w.commit();
        IntList indices = new IntList();
        for (int i = 0, n = w.getMetadata().getColumnCount(); i < n; i++) {
            indices.add(i + 1);
        }
        RecordSource rs = compileSource("xyz");
        RecordComparator rc = cc.compile(rs.getMetadata(), indices);
        RBTreeSortedRecordSource map = new RBTreeSortedRecordSource(rs, rc, 1024 * 1024, 4 * 1024 * 1024);
        sink.clear();
        printer.print(map, FACTORY_CONTAINER.getFactory());
    }
    TestUtils.assertEquals("false\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tappsicle\n" + "true\t13\t20.120000000000\t10.1500\t4\t9988908080988890\t1970-01-02T00:42:59.879Z\t902\tcomplexity made simple\tquestdb\n", sink);
}
Also used : JournalWriter(com.questdb.store.JournalWriter) RecordSource(com.questdb.ql.RecordSource) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) JournalEntryWriter(com.questdb.store.JournalEntryWriter) IntList(com.questdb.std.IntList) Test(org.junit.Test) AbstractOptimiserTest(com.questdb.parser.sql.AbstractOptimiserTest)

Example 60 with JournalStructure

use of com.questdb.store.factory.configuration.JournalStructure in project questdb by bluestreak01.

the class RBTreeSortedRecordSourceTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("xyz").$int("i").$str("str").$())) {
        int n = 100;
        Rnd rnd = new Rnd();
        for (int i = 0; i < n; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, rnd.nextInt());
            ew.putStr(1, rnd.nextChars(2));
            ew.append();
        }
        w.commit();
    }
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("dupes").$int("x").$())) {
        for (int i = 0; i < 10; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, i % 2 == 0 ? 10 : 20);
            ew.append();
        }
        JournalEntryWriter ew = w.entryWriter();
        ew.putInt(0, 30);
        ew.append();
        w.commit();
    }
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("timeseries").$double("d").$ts().$())) {
        Rnd rnd = new Rnd();
        long ts = Dates.toMillis(2016, 3, 12, 0, 0);
        for (int i = 0; i < 1000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putDouble(0, rnd.nextDouble());
            ew.putDate(1, ts + (rnd.nextPositiveInt() % Dates.DAY_MILLIS));
            ew.append();
        }
        w.commit();
    }
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) BeforeClass(org.junit.BeforeClass)

Aggregations

JournalStructure (com.questdb.store.factory.configuration.JournalStructure)74 JournalWriter (com.questdb.store.JournalWriter)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)47 Rnd (com.questdb.std.Rnd)43 Test (org.junit.Test)43 AbstractTest (com.questdb.test.tools.AbstractTest)40 BeforeClass (org.junit.BeforeClass)11 JournalException (com.questdb.std.ex.JournalException)9 Journal (com.questdb.store.Journal)9 JournalLockedException (com.questdb.ex.JournalLockedException)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 RetryLockException (com.questdb.ex.RetryLockException)5 CyclicBarrier (java.util.concurrent.CyclicBarrier)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 FactoryFullException (com.questdb.ex.FactoryFullException)4 StringSink (com.questdb.std.str.StringSink)4 Factory (com.questdb.store.factory.Factory)4 FactoryClosedException (com.questdb.ex.FactoryClosedException)3