Search in sources :

Example 26 with Rnd

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

the class GeoHashesAppendCharBenchmark method appendChar0.

@Benchmark
public void appendChar0() throws NumericException {
    Rnd rnd = new Rnd();
    long geohash = 0;
    for (int j = 0, m = 12; j < m; j++) {
        geohash = appendChar0(geohash, rnd_geochar(rnd));
    }
    if (geohash != 592262567632380556L) {
        throw new AssertionError();
    }
}
Also used : Rnd(io.questdb.std.Rnd)

Example 27 with Rnd

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

the class GeoHashesAppendCharBenchmark method appendChar1.

@Benchmark
public void appendChar1() throws NumericException {
    Rnd rnd = new Rnd();
    long geohash = 0;
    for (int j = 0, m = 12; j < m; j++) {
        geohash = appendChar1(geohash, rnd_geochar(rnd));
    }
    if (geohash != 592262567632380556L) {
        throw new AssertionError();
    }
}
Also used : Rnd(io.questdb.std.Rnd)

Example 28 with Rnd

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

the class GeoHashesSwitchOnIntVsCharBenchmark method isValidBits1.

@Benchmark
public static void isValidBits1() {
    Rnd rnd = new Rnd();
    StringSink sink = Misc.getThreadLocalBuilder();
    for (int j = 0, m = 10_000_000; j < m; j++) {
        if (!isValidBits1(rnd_geobits(rnd, sink), 0)) {
            throw new AssertionError();
        }
    }
}
Also used : Rnd(io.questdb.std.Rnd) StringSink(io.questdb.std.str.StringSink)

Example 29 with Rnd

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

the class RecordValueSinkFactoryTest method testSubset.

@Test
public void testSubset() {
    SingleColumnType keyTypes = new SingleColumnType(ColumnType.INT);
    try (TableModel model = new TableModel(configuration, "all", PartitionBy.NONE).col("int", ColumnType.INT).col("short", ColumnType.SHORT).col("byte", ColumnType.BYTE).col("double", ColumnType.DOUBLE).col("float", ColumnType.FLOAT).col("long", ColumnType.LONG).col("sym", ColumnType.SYMBOL).symbolCapacity(64).col("bool", ColumnType.BOOLEAN).col("date", ColumnType.DATE).col("ts", ColumnType.TIMESTAMP)) {
        CairoTestUtils.create(model);
    }
    final int N = 1024;
    final Rnd rnd = new Rnd();
    try (TableWriter writer = new TableWriter(configuration, "all")) {
        for (int i = 0; i < N; i++) {
            TableWriter.Row row = writer.newRow();
            row.putInt(0, rnd.nextInt());
            row.putShort(1, rnd.nextShort());
            row.putByte(2, rnd.nextByte());
            row.putDouble(3, rnd.nextDouble());
            row.putFloat(4, rnd.nextFloat());
            row.putLong(5, rnd.nextLong());
            row.putSym(6, rnd.nextChars(10));
            row.putBool(7, rnd.nextBoolean());
            row.putDate(8, rnd.nextLong());
            row.putTimestamp(9, rnd.nextLong());
            row.append();
        }
        writer.commit();
    }
    try (TableReader reader = new TableReader(configuration, "all")) {
        ArrayColumnTypes valueTypes = new ArrayColumnTypes();
        valueTypes.add(ColumnType.BOOLEAN);
        valueTypes.add(ColumnType.TIMESTAMP);
        valueTypes.add(ColumnType.INT);
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            ListColumnFilter columnFilter = new ListColumnFilter();
            columnFilter.add(8);
            columnFilter.add(10);
            columnFilter.add(7);
            RecordValueSink sink = RecordValueSinkFactory.getInstance(new BytecodeAssembler(), reader.getMetadata(), columnFilter);
            RecordCursor cursor = reader.getCursor();
            final Record record = cursor.getRecord();
            int index = 0;
            while (cursor.hasNext()) {
                MapKey key = map.withKey();
                key.putInt(index++);
                MapValue value = key.createValue();
                sink.copy(record, value);
            }
            Assert.assertEquals(N, index);
            rnd.reset();
            StaticSymbolTable symbolTable = reader.getSymbolMapReader(6);
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(i);
                MapValue value = key.findValue();
                Assert.assertNotNull(value);
                // 0
                rnd.nextInt();
                // 1
                rnd.nextShort();
                // 2
                rnd.nextByte();
                // 3
                rnd.nextDouble();
                // 4
                rnd.nextFloat();
                // 5
                rnd.nextLong();
                // 6
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(2));
                // 7
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(0));
                // 8
                rnd.nextLong();
                // 9
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(1));
            }
        }
    }
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) BytecodeAssembler(io.questdb.std.BytecodeAssembler) StaticSymbolTable(io.questdb.cairo.sql.StaticSymbolTable) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 30 with Rnd

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

the class DataFrameRecordCursorFactoryTest 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 * 4;
        for (int i = 0; i < N; i++) {
            symbols[i] = rnd.nextChars(8).toString();
        }
        rnd.reset();
        // 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 (CairoEngine engine = new CairoEngine(configuration)) {
            String value = symbols[N - 10];
            int columnIndex;
            int symbolKey;
            RecordMetadata metadata;
            try (TableReader reader = engine.getReader(AllowAllCairoSecurityContext.INSTANCE, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION)) {
                columnIndex = reader.getMetadata().getColumnIndexQuiet("b");
                symbolKey = reader.getSymbolMapReader(columnIndex).keyOf(value);
                metadata = GenericRecordMetadata.copyOf(reader.getMetadata());
            }
            SymbolIndexRowCursorFactory symbolIndexRowCursorFactory = new SymbolIndexRowCursorFactory(columnIndex, symbolKey, true, BitmapIndexReader.DIR_FORWARD, null);
            FullFwdDataFrameCursorFactory dataFrameFactory = new FullFwdDataFrameCursorFactory(engine, "x", TableUtils.ANY_TABLE_ID, TableUtils.ANY_TABLE_VERSION);
            // entity index
            final IntList columnIndexes = new IntList();
            for (int i = 0, n = metadata.getColumnCount(); i < n; i++) {
                columnIndexes.add(i);
            }
            DataFrameRecordCursorFactory factory = new DataFrameRecordCursorFactory(metadata, dataFrameFactory, symbolIndexRowCursorFactory, false, null, false, columnIndexes, null);
            SqlExecutionContext sqlExecutionContext = new SqlExecutionContextImpl(engine, 1).with(AllowAllCairoSecurityContext.INSTANCE, null, null, -1, null);
            try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
                Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    TestUtils.assertEquals(value, record.getSym(1));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Rnd(io.questdb.std.Rnd) IntList(io.questdb.std.IntList) RecordMetadata(io.questdb.cairo.sql.RecordMetadata) SqlExecutionContextImpl(io.questdb.griffin.SqlExecutionContextImpl) SqlExecutionContext(io.questdb.griffin.SqlExecutionContext) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Aggregations

Rnd (io.questdb.std.Rnd)76 Test (org.junit.Test)49 Record (io.questdb.cairo.sql.Record)32 RecordCursor (io.questdb.cairo.sql.RecordCursor)29 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)28 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)24 TableWriter (io.questdb.cairo.TableWriter)23 Path (io.questdb.std.str.Path)10 RuntimeIntervalModel (io.questdb.griffin.model.RuntimeIntervalModel)4 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 DataFrameCursor (io.questdb.cairo.sql.DataFrameCursor)2 ReaderOutOfDateException (io.questdb.cairo.sql.ReaderOutOfDateException)2 RowCursor (io.questdb.cairo.sql.RowCursor)2 StaticSymbolTable (io.questdb.cairo.sql.StaticSymbolTable)2 LineTcpSender (io.questdb.cutlass.line.LineTcpSender)2 SqlExecutionContextImpl (io.questdb.griffin.SqlExecutionContextImpl)2 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)2 BinarySequence (io.questdb.std.BinarySequence)2 BytecodeAssembler (io.questdb.std.BytecodeAssembler)2 FilesFacade (io.questdb.std.FilesFacade)2