Search in sources :

Example 6 with Rnd

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

the class IntLongPriorityQueueTest method testIndexSort.

@Test
public void testIndexSort() throws Exception {
    final int nStreams = 16;
    Rnd rnd = new Rnd();
    int totalLen = 0;
    try (KVIndex index = new KVIndex(indexFile, totalKeys, totalValues, 1, JournalMode.APPEND, 0, false)) {
        for (int i = 0; i < nStreams; i++) {
            long[] values = new long[rnd.nextPositiveInt() % 1000];
            totalLen += values.length;
            for (int j = 0; j < values.length; j++) {
                values[j] = rnd.nextPositiveLong() % 100;
            }
            Arrays.sort(values);
            for (int j = 0; j < values.length; j++) {
                index.add(i, values[j]);
            }
            index.commit();
        }
        long[] expected = new long[totalLen];
        int p = 0;
        for (int i = 0; i < nStreams; i++) {
            IndexCursor c = index.fwdCursor(i);
            while (c.hasNext()) {
                expected[p++] = c.next();
            }
        }
        Arrays.sort(expected);
        IntLongPriorityQueue heap = new IntLongPriorityQueue(nStreams);
        IndexCursor[] cursors = new IndexCursor[nStreams];
        for (int i = 0; i < nStreams; i++) {
            cursors[i] = index.newFwdCursor(i);
            if (cursors[i].hasNext()) {
                heap.add(i, cursors[i].next());
            }
        }
        p = 0;
        while (heap.hasNext()) {
            int idx = heap.popIndex();
            long v;
            if (cursors[idx].hasNext()) {
                v = heap.popAndReplace(idx, cursors[idx].next());
            } else {
                v = heap.popValue();
            }
            Assert.assertEquals(expected[p++], v);
        }
    }
}
Also used : IndexCursor(com.questdb.store.IndexCursor) Rnd(com.questdb.std.Rnd) IntLongPriorityQueue(com.questdb.std.IntLongPriorityQueue) KVIndex(com.questdb.store.KVIndex) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 7 with Rnd

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

the class PerformanceTest method testCairoPerformance.

@Test
public void testCairoPerformance() throws NumericException {
    int count = 10;
    long t = 0;
    long result;
    CairoConfiguration configuration = new DefaultCairoConfiguration(getFactory().getConfiguration().getJournalBase().getAbsolutePath());
    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" };
    try (TableModel model = new TableModel(configuration, "quote", PartitionBy.NONE).timestamp().col("sym", ColumnType.SYMBOL).col("bid", ColumnType.DOUBLE).col("ask", ColumnType.DOUBLE).col("bidSize", ColumnType.INT).col("askSize", ColumnType.INT).col("mode", ColumnType.SYMBOL).symbolCapacity(2).col("ex", ColumnType.SYMBOL).symbolCapacity(2)) {
        CairoTestUtils.create(model);
    }
    try (TableWriter w = new TableWriter(configuration, "quote")) {
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            w.truncate();
            long timestamp = DateFormatUtils.parseDateTime("2013-10-05T10:00:00.000Z");
            Rnd r = new Rnd();
            int n = symbols.length - 1;
            for (int i1 = 0; i1 < TEST_DATA_SIZE; i1++) {
                TableWriter.Row row = w.newRow(timestamp);
                row.putSym(1, symbols[Math.abs(r.nextInt() % n)]);
                row.putDouble(2, Math.abs(r.nextDouble()));
                row.putDouble(3, Math.abs(r.nextDouble()));
                row.putInt(4, Math.abs(r.nextInt()));
                row.putInt(5, Math.abs(r.nextInt()));
                row.putSym(6, "LXE");
                row.putSym(7, "Fast trading");
                row.append();
                timestamp += (long) 1000;
            }
            w.commit();
        }
        result = System.nanoTime() - t;
    }
    LOG.info().$("Cairo append (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result / count)).$("ms").$();
    try (TableReader reader = new TableReader(configuration, "quote")) {
        for (int i = -count; i < count; i++) {
            if (i == 0) {
                t = System.nanoTime();
            }
            RecordCursor cursor = reader.getCursor();
            while (cursor.hasNext()) {
                Record r = cursor.next();
                r.getDate(0);
                r.getSym(1);
                r.getDouble(2);
                r.getDouble(3);
                r.getInt(4);
                r.getInt(5);
                r.getSym(6);
                r.getSym(7);
            }
        }
        result = (System.nanoTime() - t) / count;
    }
    LOG.info().$("Cairo read (1M): ").$(TimeUnit.NANOSECONDS.toMillis(result)).$("ms").$();
}
Also used : Rnd(com.questdb.std.Rnd) AbstractTest(com.questdb.test.tools.AbstractTest) Test(org.junit.Test)

Example 8 with Rnd

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

the class BitmapIndexNullReaderTest method testCursor.

@Test
public void testCursor() {
    final Rnd rnd = new Rnd();
    for (int i = 0; i < 10; i++) {
        int n = rnd.nextPositiveInt() % 1024;
        int m = n;
        RowCursor cursor = reader.getCursor(0, n);
        while (cursor.hasNext()) {
            Assert.assertEquals(m--, cursor.next());
        }
        Assert.assertEquals(-1, m);
    }
}
Also used : Rnd(com.questdb.std.Rnd) RowCursor(com.questdb.common.RowCursor) Test(org.junit.Test)

Example 9 with Rnd

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

the class FullTableFrameCursorFactoryTest method testFactory.

@Test
public void testFactory() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 100;
        // separate two symbol columns with primitive. It will make problems apparent if index does not shift correctly
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.DAY).col("a", ColumnType.STRING).col("b", ColumnType.SYMBOL).indexed(true, N / 4).col("i", ColumnType.INT).col("c", ColumnType.SYMBOL).indexed(true, N / 4).timestamp()) {
            CairoTestUtils.create(model);
        }
        final Rnd rnd = new Rnd();
        final String[] symbols = new String[N];
        final int M = 1000;
        final long increment = 1000000 * 60L * 10;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        // prepare the data
        long timestamp = 0;
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < M; i++) {
                TableWriter.Row row = writer.newRow(timestamp += increment);
                row.putStr(0, rnd.nextChars(20));
                row.putSym(1, symbols[rnd.nextPositiveInt() % N]);
                row.putInt(2, rnd.nextInt());
                row.putSym(3, symbols[rnd.nextPositiveInt() % N]);
                row.append();
            }
            writer.commit();
        }
        try (Engine engine = new Engine(configuration)) {
            FullTableFrameCursorFactory factory = new FullTableFrameCursorFactory(engine, "x");
            long count = 0;
            try (DataFrameCursor cursor = factory.getCursor()) {
                while (cursor.hasNext()) {
                    DataFrame frame = cursor.next();
                    count += frame.getRowHi() - frame.getRowLo();
                }
            }
            Assert.assertEquals(0, engine.getBusyReaderCount());
            Assert.assertEquals(M, count);
        }
    });
}
Also used : DataFrameCursor(com.questdb.cairo.sql.DataFrameCursor) Rnd(com.questdb.std.Rnd) DataFrame(com.questdb.cairo.sql.DataFrame) Test(org.junit.Test)

Example 10 with Rnd

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

the class ResamplingTest 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").$date("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 orders2 = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders2").$int("orderId").$int("customerId").$int("productId").$str("employeeId").$date("orderDate").$int("quantity").$double("price").$float("rate").$date("basketDate").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");
        long timestamp2 = DateFormatUtils.parseDateTime("2014-05-03T00:15:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders2.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.putDate(8, timestamp2 + tsIncrement);
            w.append();
        }
        orders2.commit();
    }
    try (JournalWriter orders2 = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders4").$int("orderId").$int("customerId").$int("productId").$sym("employeeId").$date("orderDate").$int("quantity").$double("price").$float("rate").$ts("basketDate").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");
        long timestamp2 = DateFormatUtils.parseDateTime("2014-05-03T00:15:00.000Z");
        int tsIncrement = 10000;
        int orderId = 0;
        for (int i = 0; i < recordCount; i++) {
            JournalEntryWriter w = orders2.entryWriter();
            w.putInt(0, ++orderId);
            w.putInt(1, rnd.nextPositiveInt() % 500);
            w.putInt(2, rnd.nextPositiveInt() % 200);
            w.putSym(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.putDate(8, timestamp2 + tsIncrement);
            w.append();
        }
        orders2.commit();
    }
    JournalWriter orders3 = FACTORY_CONTAINER.getFactory().writer(new JournalStructure("orders3").$int("orderId").$int("customerId").$int("productId").$str("employeeId").$int("quantity").$double("price").$float("rate").recordCountHint(recordCount).$());
    orders3.close();
}
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

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