Search in sources :

Example 51 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class AggregationTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    int recordCount = 10000;
    int employeeCount = 10;
    try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$int("productId").$str("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").recordCountHint(recordCount).$())) {
        Rnd rnd = new Rnd();
        String[] employees = new String[employeeCount];
        for (int i = 0; i < employees.length; i++) {
            employees[i] = rnd.nextString(9);
        }
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders.entryWriter();
            w.putInt(0, ++orderId);
            w.putInt(1, rnd.nextPositiveInt() % 500);
            w.putInt(2, rnd.nextPositiveInt() % 200);
            w.putStr(3, employees[rnd.nextPositiveInt() % employeeCount]);
            w.putDate(4, timestamp += tsIncrement);
            w.putInt(5, rnd.nextPositiveInt());
            w.putDouble(6, rnd.nextDouble());
            w.putFloat(7, rnd.nextFloat());
            w.append();
        }
        orders.commit();
    }
    try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars").$int("galaxy").$int("star").$double("diameter").$())) {
        Rnd rnd = new Rnd();
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
            w.putInt(0, rnd.nextPositiveInt() % 10);
            w.putInt(1, rnd.nextPositiveInt());
            int dividend = (rnd.nextPositiveInt() % 10);
            w.putDouble(2, Double.MAX_VALUE / (double) (dividend == 0 ? 1 : dividend));
            w.append();
        }
        stars.commit();
    }
    try (JournalWriter stars = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("stars2").$int("galaxy").$int("star").$double("diameter").$())) {
        Rnd rnd = new Rnd();
        double r = Math.sqrt(Double.MAX_VALUE);
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = stars.entryWriter(timestamp += tsIncrement);
            w.putInt(0, rnd.nextPositiveInt() % 10);
            w.putInt(1, rnd.nextPositiveInt());
            int dividend = (rnd.nextPositiveInt() % 10);
            w.putDouble(2, r / (double) (dividend == 0 ? 1 : dividend));
            w.append();
        }
        stars.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)

Example 52 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class NullAggregationTest method createTabWithNaNs2.

private static void createTabWithNaNs2() throws JournalException, NumericException {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$long("z").$int("w").$str("a").$ts())) {
        Rnd rnd = new Rnd();
        int n = 128;
        ObjHashSet<String> names = getNames(rnd, n);
        int mask = n - 1;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 10000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putStr(0, names.get(rnd.nextInt() & mask));
            ew.putDouble(1, rnd.nextDouble());
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(2);
            } else {
                ew.putDouble(2, rnd.nextDouble());
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(3);
            } else {
                ew.putLong(3, rnd.nextLong() % 500);
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(4);
            } else {
                ew.putInt(4, rnd.nextInt() % 500);
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(5);
            } else {
                ew.putStr(5, names.get(rnd.nextInt() & mask));
            }
            ew.putDate(6, t += (60 * 60 * 1000));
            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)

Example 53 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class NullCountingTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    int recordCount = 10000;
    int productCount = 200;
    int employeeCount = 10;
    try (JournalWriter orders = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders").$int("orderId").$int("customerId").$str("productId").$sym("employeeId").$ts("orderDate").$int("quantity").$double("price").$float("rate").$long("x").recordCountHint(recordCount).$())) {
        Rnd rnd = new Rnd();
        String[] employees = new String[employeeCount];
        for (int i = 0; i < employees.length; i++) {
            if (rnd.nextPositiveInt() % 10 == 0) {
                employees[i] = null;
            } else {
                employees[i] = rnd.nextString(9);
            }
        }
        String[] productId = new String[productCount];
        for (int i = 0; i < productId.length; i++) {
            if (rnd.nextPositiveInt() % 30 == 0) {
                productId[i] = null;
            } else {
                productId[i] = rnd.nextString(9);
            }
        }
        long timestamp = DateFormatUtils.parseDateTime("2014-05-04T10:30:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders.entryWriter();
            w.putInt(0, ++orderId);
            w.putInt(1, rnd.nextPositiveInt() % 500);
            w.putStr(2, productId[rnd.nextPositiveInt() % productCount]);
            w.putSym(3, employees[rnd.nextPositiveInt() % employeeCount]);
            w.putDate(4, timestamp += tsIncrement);
            w.putInt(5, rnd.nextPositiveInt() % 10 == 0 ? Numbers.INT_NaN : rnd.nextPositiveInt());
            w.putDouble(6, rnd.nextPositiveInt() % 10 == 0 ? Double.NaN : rnd.nextDouble());
            w.putFloat(7, rnd.nextPositiveInt() % 10 == 0 ? Float.NaN : rnd.nextFloat());
            w.putLong(8, rnd.nextPositiveInt() % 10 == 0 ? Numbers.LONG_NaN : rnd.nextLong());
            w.append();
        }
        orders.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)

Example 54 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class QueryDateTest method createTab.

private void createTab() throws JournalException, NumericException {
    try (JournalWriter w = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$date("z").$date("w").$ts())) {
        Rnd rnd = new Rnd();
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        long time1 = DateFormatUtils.parseDateTime("2015-10-03T00:00:00.000Z");
        for (int i = 0; i < 10000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putStr(0, rnd.nextChars(15));
            ew.putDouble(1, rnd.nextDouble());
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(2);
            } else {
                ew.putDouble(2, rnd.nextDouble());
            }
            if (rnd.nextPositiveInt() % 10 == 0) {
                ew.putNull(3);
            } else {
                ew.putDate(3, time1 + rnd.nextLong() % 5000000);
            }
            ew.putDate(5, t += 10);
            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)

Example 55 with JournalWriter

use of com.questdb.store.JournalWriter in project questdb by bluestreak01.

the class SingleJournalQueryTest method testSearchByIntIdUnindexed.

@Test
public void testSearchByIntIdUnindexed() throws Exception {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$int("id").$double("x").$double("y").$ts())) {
        Rnd rnd = new Rnd();
        int[] ids = new int[4096];
        for (int i = 0; i < ids.length; i++) {
            ids[i] = rnd.nextPositiveInt();
        }
        int mask = ids.length - 1;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 100000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, ids[rnd.nextInt() & mask]);
            ew.putDouble(1, rnd.nextDouble());
            ew.putDouble(2, rnd.nextDouble());
            ew.putDate(3, t += 10);
            ew.append();
        }
        w.commit();
    }
    final String expected = "1148688404\t19.165769577026\t0.002435457427\t2015-03-12T00:00:10.150Z\n" + "1148688404\t0.000000444469\t2.694594800472\t2015-03-12T00:00:28.400Z\n" + "1148688404\t-640.000000000000\t-1024.000000000000\t2015-03-12T00:01:06.260Z\n" + "1148688404\t0.000000009509\t320.000000000000\t2015-03-12T00:01:26.010Z\n" + "1148688404\t0.000107977266\t362.467056274414\t2015-03-12T00:01:57.750Z\n" + "1148688404\t0.000000022366\t-451.815429687500\t2015-03-12T00:02:32.560Z\n" + "1148688404\t0.000003631694\t152.575393676758\t2015-03-12T00:02:35.210Z\n" + "1148688404\t-458.523437500000\t0.003299130592\t2015-03-12T00:03:09.590Z\n" + "1148688404\t-576.000000000000\t0.000000005352\t2015-03-12T00:03:15.080Z\n" + "1148688404\t0.000000010009\t0.000000336123\t2015-03-12T00:03:33.830Z\n" + "1148688404\t0.012756480370\t0.191264979541\t2015-03-12T00:03:56.200Z\n" + "1148688404\t-793.000000000000\t6.048339843750\t2015-03-12T00:04:01.350Z\n" + "1148688404\t0.000144788552\t10.723476886749\t2015-03-12T00:04:48.380Z\n" + "1148688404\t-467.990722656250\t5.262818336487\t2015-03-12T00:04:52.710Z\n" + "1148688404\t0.031378546730\t149.346038818359\t2015-03-12T00:05:01.020Z\n" + "1148688404\t0.000741893891\t-27.789062500000\t2015-03-12T00:05:19.110Z\n" + "1148688404\t0.000000032685\t0.000000002490\t2015-03-12T00:05:26.610Z\n" + "1148688404\t0.652305364609\t0.000000029041\t2015-03-12T00:06:56.860Z\n" + "1148688404\t-894.000000000000\t51.695074081421\t2015-03-12T00:08:46.620Z\n" + "1148688404\t695.000000000000\t0.145211979747\t2015-03-12T00:09:22.390Z\n" + "1148688404\t-334.488891601563\t0.000000393977\t2015-03-12T00:09:29.860Z\n" + "1148688404\t7.933303117752\t0.000516850792\t2015-03-12T00:10:13.730Z\n" + "1148688404\t435.498107910156\t1.287820875645\t2015-03-12T00:10:30.240Z\n" + "1148688404\t961.880340576172\t0.000168625862\t2015-03-12T00:10:41.190Z\n" + "1148688404\t-84.978515625000\t0.051617769524\t2015-03-12T00:10:46.200Z\n" + "1148688404\t0.000000544715\t0.000328194423\t2015-03-12T00:10:52.510Z\n" + "1148688404\t512.000000000000\t875.250000000000\t2015-03-12T00:11:46.390Z\n" + "1148688404\t0.000000010856\t0.028837248683\t2015-03-12T00:12:15.140Z\n" + "1148688404\t0.000027862162\t-896.000000000000\t2015-03-12T00:12:28.700Z\n" + "1148688404\t0.000000003071\t0.000025084717\t2015-03-12T00:12:36.370Z\n" + "1148688404\t0.000040687404\t0.007985642878\t2015-03-12T00:12:42.940Z\n" + "1148688404\t-961.937500000000\t-849.000000000000\t2015-03-12T00:12:49.940Z\n" + "1148688404\t0.000384466533\t87.682281494141\t2015-03-12T00:14:11.980Z\n" + "1148688404\t0.000000309420\t448.000000000000\t2015-03-12T00:15:38.730Z\n" + "1148688404\t29.022820472717\t-123.758422851563\t2015-03-12T00:16:30.770Z\n";
    assertThat(expected, "select id, x, y, timestamp from tab where id = 1148688404");
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

JournalWriter (com.questdb.store.JournalWriter)93 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)60 JournalEntryWriter (com.questdb.store.JournalEntryWriter)59 AbstractTest (com.questdb.test.tools.AbstractTest)54 Test (org.junit.Test)52 Rnd (com.questdb.std.Rnd)42 BeforeClass (org.junit.BeforeClass)12 CountDownLatch (java.util.concurrent.CountDownLatch)9 RecordCursor (com.questdb.common.RecordCursor)6 JournalException (com.questdb.std.ex.JournalException)6 Record (com.questdb.common.Record)5 RecordSource (com.questdb.ql.RecordSource)5 Factory (com.questdb.store.factory.Factory)5 BootstrapEnv (com.questdb.BootstrapEnv)4 ServerConfiguration (com.questdb.ServerConfiguration)4 JournalLockedException (com.questdb.ex.JournalLockedException)4 ClientConfig (com.questdb.net.ha.config.ClientConfig)4 ServerConfig (com.questdb.net.ha.config.ServerConfig)4 ServerNode (com.questdb.net.ha.config.ServerNode)4 StringSink (com.questdb.std.str.StringSink)4