Search in sources :

Example 51 with Rnd

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

the class SingleJournalQueryTest method testIntMultiplication.

@Test
public void testIntMultiplication() throws Exception {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$int("x").$int("y").$str("z").$ts())) {
        Rnd rnd = new Rnd();
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 1000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putInt(0, rnd.nextInt() & 255);
            ew.putInt(1, rnd.nextInt() & 255);
            ew.putStr(2, rnd.nextString(4));
            ew.putDate(3, t += 10);
            ew.append();
        }
        w.commit();
    }
    final String expected1 = "29512\t-129\t119\t248\tCBJF\t2015-03-12T00:00:01.370Z\n" + "30906\t49\t202\t153\tCJZJ\t2015-03-12T00:00:07.470Z\n" + "2508\t113\t132\t19\tCGCJ\t2015-03-12T00:00:09.070Z\n";
    assertThat(expected1, "select x * y, x - y, x, y, z, timestamp from tab where z ~ '^C.*J+'");
}
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)

Example 52 with Rnd

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

the class SingleJournalQueryTest method testIntComparison.

@Test
public void testIntComparison() throws Exception {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$sym("id").index().buckets(128).$double("x").$double("y").$int("i1").$int("i2").$ts())) {
        Rnd rnd = new Rnd();
        ObjHashSet<String> names = getNames(rnd, 128);
        int mask = 127;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 10000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putSym(0, names.get(rnd.nextInt() & mask));
            ew.putDouble(1, rnd.nextDouble());
            ew.putDouble(2, rnd.nextDouble());
            ew.putInt(3, rnd.nextInt() & 63);
            ew.putInt(4, rnd.nextInt() & 63);
            ew.putDate(5, t += 10);
            ew.append();
        }
        w.commit();
    }
    final String expected1 = "XSPEPTTKIBWFCKD\t290.742401123047\t0.000001862155\t2\t1\n" + "XSPEPTTKIBWFCKD\t294.856933593750\t-539.875854492188\t55\t42\n" + "XSPEPTTKIBWFCKD\t422.000000000000\t0.000001386965\t58\t54\n";
    assertThat(expected1, "select id,x,y,i1,i2 from tab where i1 >= i2 and x>=y  and x>=i1 and id = 'XSPEPTTKIBWFCKD'");
    final String expected2 = "XSPEPTTKIBWFCKD\t0.007556580706\t-444.759765625000\t14\t20\n" + "XSPEPTTKIBWFCKD\t0.002191273379\t-587.421875000000\t1\t33\n" + "XSPEPTTKIBWFCKD\t0.000000050401\t-873.569183349609\t34\t41\n" + "XSPEPTTKIBWFCKD\t0.000000002468\t-1009.435546875000\t7\t35\n" + "XSPEPTTKIBWFCKD\t0.000000134022\t0.000000010189\t38\t44\n" + "XSPEPTTKIBWFCKD\t0.053807163611\t0.000000005584\t18\t40\n" + "XSPEPTTKIBWFCKD\t307.605468750000\t0.000000032526\t5\t49\n" + "XSPEPTTKIBWFCKD\t588.000000000000\t0.000029410815\t42\t62\n" + "XSPEPTTKIBWFCKD\t102.474868774414\t-704.000000000000\t61\t63\n" + "XSPEPTTKIBWFCKD\t0.000166006441\t-400.250000000000\t23\t49\n" + "XSPEPTTKIBWFCKD\t0.006018321496\t0.000000163838\t21\t55\n" + "XSPEPTTKIBWFCKD\t82.432384490967\t0.000043923766\t36\t45\n" + "XSPEPTTKIBWFCKD\t256.000000000000\t-648.000000000000\t12\t46\n" + "XSPEPTTKIBWFCKD\t384.875000000000\t0.000049836333\t23\t46\n" + "XSPEPTTKIBWFCKD\t0.000000883287\t-844.890625000000\t4\t24\n" + "XSPEPTTKIBWFCKD\t0.103299163282\t0.000076360289\t16\t54\n" + "XSPEPTTKIBWFCKD\t0.003647925099\t0.000000019679\t15\t38\n" + "XSPEPTTKIBWFCKD\t0.000589750460\t0.000000023659\t4\t39\n";
    assertThat(expected2, "select id,x,y,i1,i2 from tab where i1 < i2 and x>=y  and y<i1 and id = 'XSPEPTTKIBWFCKD'");
}
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)

Example 53 with Rnd

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

the class SingleJournalQueryTest method createTab.

private void createTab() throws JournalException, NumericException {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$ts())) {
        Rnd rnd = new Rnd();
        ObjHashSet<String> names = getNames(rnd, 1024);
        int mask = 1023;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 100000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            ew.putStr(0, names.get(rnd.nextInt() & mask));
            ew.putDouble(1, rnd.nextDouble());
            ew.putDouble(2, rnd.nextDouble());
            ew.putDate(3, 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 54 with Rnd

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

the class SingleJournalQueryTest method createTabNoNaNs.

private void createTabNoNaNs() throws JournalException, NumericException {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$str("id").$double("x").$double("y").$long("z").$int("w").$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());
            ew.putDouble(2, rnd.nextDouble());
            ew.putLong(3, rnd.nextLong());
            ew.putInt(4, rnd.nextInt());
            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 Rnd

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

the class SingleJournalQueryTest method testSearchIndexedStrNull.

@Test
public void testSearchIndexedStrNull() throws Exception {
    try (JournalWriter w = getFactory().writer(new JournalStructure("tab").$str("id").index().buckets(128).$double("x").$double("y").$ts())) {
        Rnd rnd = new Rnd();
        ObjHashSet<String> names = new ObjHashSet<>();
        for (int i = 0; i < 128; i++) {
            names.add(rnd.nextString(15));
        }
        int mask = 127;
        long t = DateFormatUtils.parseDateTime("2015-03-12T00:00:00.000Z");
        for (int i = 0; i < 10000; i++) {
            JournalEntryWriter ew = w.entryWriter();
            if ((rnd.nextPositiveInt() % 10) == 0) {
                ew.putNull(0);
            } else {
                ew.putStr(0, names.get(rnd.nextInt() & mask));
            }
            ew.putDouble(1, rnd.nextDouble());
            ew.putDouble(2, rnd.nextDouble());
            ew.putDate(3, t += 10);
            ew.append();
        }
        w.commit();
    }
    assertNullSearch();
}
Also used : JournalWriter(com.questdb.store.JournalWriter) JournalStructure(com.questdb.store.factory.configuration.JournalStructure) Rnd(com.questdb.std.Rnd) ObjHashSet(com.questdb.std.ObjHashSet) JournalEntryWriter(com.questdb.store.JournalEntryWriter) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Aggregations

Rnd (com.questdb.std.Rnd)82 Test (org.junit.Test)50 JournalEntryWriter (com.questdb.store.JournalEntryWriter)43 JournalStructure (com.questdb.store.factory.configuration.JournalStructure)43 JournalWriter (com.questdb.store.JournalWriter)42 AbstractTest (com.questdb.test.tools.AbstractTest)30 BeforeClass (org.junit.BeforeClass)8 Path (com.questdb.std.str.Path)7 JournalException (com.questdb.std.ex.JournalException)6 StringSink (com.questdb.std.str.StringSink)5 ObjList (com.questdb.std.ObjList)4 Factory (com.questdb.store.factory.Factory)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 NumericException (com.questdb.common.NumericException)3 Record (com.questdb.common.Record)3 RecordCursor (com.questdb.common.RecordCursor)3 Quote (com.questdb.model.Quote)3 ObjHashSet (com.questdb.std.ObjHashSet)3 File (java.io.File)3 BootstrapEnv (com.questdb.BootstrapEnv)2