Search in sources :

Example 36 with Rnd

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

the class ToCharBinVFunctionFactoryTest method testDanglingLastLine.

@Test
public void testDanglingLastLine() throws SqlException {
    Rnd rnd = new Rnd();
    call(rnd.nextBytes(150)).andAssert("00000000 56 54 4a 57 43 50 53 57 48 59 52 58 50 45 48 4e\n" + "00000010 52 58 47 5a 53 58 55 58 49 42 42 54 47 50 47 57\n" + "00000020 46 46 59 55 44 45 59 59 51 45 48 42 48 46 4f 57\n" + "00000030 4c 50 44 58 59 53 42 45 4f 55 4f 4a 53 48 52 55\n" + "00000040 45 44 52 51 51 55 4c 4f 46 4a 47 45 54 4a 52 53\n" + "00000050 5a 53 52 59 52 46 42 56 54 4d 48 47 4f 4f 5a 5a\n" + "00000060 56 44 5a 4a 4d 59 49 43 43 58 5a 4f 55 49 43 57\n" + "00000070 45 4b 47 48 56 55 56 53 44 4f 54 53 45 44 59 59\n" + "00000080 43 54 47 51 4f 4c 59 58 57 43 4b 59 4c 53 55 57\n" + "00000090 44 53 57 55 47 53");
}
Also used : Rnd(io.questdb.std.Rnd) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest) Test(org.junit.Test)

Example 37 with Rnd

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

the class ToCharBinVFunctionFactoryTest method testExactLines.

@Test
public void testExactLines() throws SqlException {
    Rnd rnd = new Rnd();
    call(rnd.nextBytes(256)).andAssert("00000000 56 54 4a 57 43 50 53 57 48 59 52 58 50 45 48 4e\n" + "00000010 52 58 47 5a 53 58 55 58 49 42 42 54 47 50 47 57\n" + "00000020 46 46 59 55 44 45 59 59 51 45 48 42 48 46 4f 57\n" + "00000030 4c 50 44 58 59 53 42 45 4f 55 4f 4a 53 48 52 55\n" + "00000040 45 44 52 51 51 55 4c 4f 46 4a 47 45 54 4a 52 53\n" + "00000050 5a 53 52 59 52 46 42 56 54 4d 48 47 4f 4f 5a 5a\n" + "00000060 56 44 5a 4a 4d 59 49 43 43 58 5a 4f 55 49 43 57\n" + "00000070 45 4b 47 48 56 55 56 53 44 4f 54 53 45 44 59 59\n" + "00000080 43 54 47 51 4f 4c 59 58 57 43 4b 59 4c 53 55 57\n" + "00000090 44 53 57 55 47 53 48 4f 4c 4e 56 54 49 51 42 5a\n" + "000000a0 58 49 4f 56 49 4b 4a 53 4d 53 53 55 51 53 52 4c\n" + "000000b0 54 4b 56 56 53 4a 4f 4a 49 50 48 5a 45 50 49 48\n" + "000000c0 56 4c 54 4f 56 4c 4a 55 4d 4c 47 4c 48 4d 4c 4c\n" + "000000d0 45 4f 59 50 48 52 49 50 5a 49 4d 4e 5a 5a 52 4d\n" + "000000e0 46 4d 42 45 5a 47 48 57 56 44 4b 46 4c 4f 50 4a\n" + "000000f0 4f 58 50 4b 52 47 49 49 48 59 48 42 4f 51 4d 59");
}
Also used : Rnd(io.questdb.std.Rnd) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest) Test(org.junit.Test)

Example 38 with Rnd

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

the class AbstractO3Test method setUp.

@Before
public void setUp() {
    SharedRandom.RANDOM.set(new Rnd());
    // instantiate these paths so that they are not included in memory leak test
    Path.PATH.get();
    Path.PATH2.get();
    TestUtils.createTestPath(root);
}
Also used : Rnd(io.questdb.std.Rnd)

Example 39 with Rnd

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

the class RecordValueSinkFactoryTest method testAllSupportedTypes.

@Test
public void testAllSupportedTypes() {
    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")) {
        final SymbolAsIntTypes valueTypes = new SymbolAsIntTypes().of(reader.getMetadata());
        try (final Map map = new FastMap(Numbers.SIZE_1MB, keyTypes, valueTypes, N, 0.5, 100)) {
            EntityColumnFilter columnFilter = new EntityColumnFilter();
            columnFilter.of(reader.getMetadata().getColumnCount());
            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);
                Assert.assertEquals(rnd.nextInt(), value.getInt(0));
                Assert.assertEquals(rnd.nextShort(), value.getShort(1));
                Assert.assertEquals(rnd.nextByte(), value.getByte(2));
                Assert.assertEquals(rnd.nextDouble(), value.getDouble(3), 0.000001);
                Assert.assertEquals(rnd.nextFloat(), value.getFloat(4), 0.000001f);
                Assert.assertEquals(rnd.nextLong(), value.getLong(5));
                Assert.assertEquals(symbolTable.keyOf(rnd.nextChars(10)), value.getInt(6));
                Assert.assertEquals(rnd.nextBoolean(), value.getBool(7));
                Assert.assertEquals(rnd.nextLong(), value.getDate(8));
                Assert.assertEquals(rnd.nextLong(), value.getTimestamp(9));
            }
        }
    }
}
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 40 with Rnd

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

the class Mig608 method migrate.

static void migrate(MigrationContext migrationContext) {
    // META_COLUMN_DATA_SIZE = 16 -> 32;
    // TX_OFFSET_MAP_WRITER_COUNT = 72 -> 128
    final FilesFacade ff = migrationContext.getFf();
    final Path path = migrationContext.getTablePath();
    final int plen = path.length();
    path.concat(META_FILE_NAME).$();
    if (!ff.exists(path)) {
        MigrationActions.LOG.error().$("meta file does not exist, nothing to migrate [path=").$(path).I$();
        return;
    }
    // modify metadata
    try (final MemoryMARW rwMem = migrationContext.getRwMemory()) {
        final long thatMetaColumnDataSize = 16;
        final long thisMetaColumnDataSize = 32;
        rwMem.of(ff, path, ff.getPageSize(), ff.length(path), MemoryTag.NATIVE_DEFAULT);
        // column count
        final int columnCount = rwMem.getInt(TableUtils.META_OFFSET_COUNT);
        long offset = TableUtils.META_OFFSET_COLUMN_TYPES;
        // 32L here is TableUtils.META_COLUMN_DATA_SIZE at the time of writing this migration
        long newNameOffset = offset + thisMetaColumnDataSize * columnCount;
        // the intent is to resize the _meta file and move the variable length (names) segment
        // to do that we need to work out size of the variable length segment first
        long oldNameOffset = offset + thatMetaColumnDataSize * columnCount;
        long o = oldNameOffset;
        for (int i = 0; i < columnCount; i++) {
            int len = rwMem.getStrLen(o);
            o += Vm.getStorageLength(len);
        }
        final long nameSegmentLen = o - oldNameOffset;
        // resize the file
        rwMem.extend(newNameOffset + nameSegmentLen);
        // move name segment
        Vect.memmove(rwMem.addressOf(newNameOffset), rwMem.addressOf(oldNameOffset), nameSegmentLen);
        // copy column information in reverse order
        o = offset + thatMetaColumnDataSize * (columnCount - 1);
        long o2 = offset + thisMetaColumnDataSize * (columnCount - 1);
        final Rnd rnd = SharedRandom.getRandom(migrationContext.getConfiguration());
        while (o >= offset) {
            // type
            rwMem.putInt(o2, rwMem.getInt(o));
            // flags
            rwMem.putLong(o2 + 4, rwMem.getInt(o + 4));
            // index block capacity
            rwMem.putInt(o2 + 12, rwMem.getInt(o + 12));
            // column hash
            rwMem.putLong(o2 + 20, rnd.nextLong());
            o -= thatMetaColumnDataSize;
            o2 -= thisMetaColumnDataSize;
        }
        rwMem.jumpTo(newNameOffset + nameSegmentLen);
    }
    // update _txn file
    path.trimTo(plen).concat(TXN_FILE_NAME).$();
    if (!ff.exists(path)) {
        MigrationActions.LOG.error().$("tx file does not exist, nothing to migrate [path=").$(path).I$();
        return;
    }
    EngineMigration.backupFile(ff, path, migrationContext.getTablePath2(), TXN_FILE_NAME, 422);
    MigrationActions.LOG.debug().$("opening for rw [path=").$(path).I$();
    try (MemoryMARW txMem = migrationContext.createRwMemoryOf(ff, path.$())) {
        // calculate size of the _txn file
        final long thatTxOffsetMapWriterCount = 72;
        final long thisTxOffsetMapWriterCount = 128;
        final int longsPerAttachedPartition = 4;
        int symbolCount = txMem.getInt(thatTxOffsetMapWriterCount);
        int partitionTableSize = txMem.getInt(thatTxOffsetMapWriterCount + 4 + symbolCount * 8L) * 8 * longsPerAttachedPartition;
        // resize existing file:
        // thisTxOffsetMapWriterCount + symbolCount + symbolData + partitionTableEntryCount + partitionTableSize
        long thatSize = thatTxOffsetMapWriterCount + 4 + symbolCount * 8L + 4L + partitionTableSize;
        long thisSize = thisTxOffsetMapWriterCount + 4 + symbolCount * 8L + 4L + partitionTableSize;
        txMem.extend(thisSize);
        txMem.jumpTo(thisSize);
        Vect.memmove(txMem.addressOf(thisTxOffsetMapWriterCount), txMem.addressOf(thatTxOffsetMapWriterCount), thatSize - thatTxOffsetMapWriterCount);
        // zero out reserved area
        Vect.memset(txMem.addressOf(thatTxOffsetMapWriterCount), thisTxOffsetMapWriterCount - thatTxOffsetMapWriterCount, 0);
    }
}
Also used : Path(io.questdb.std.str.Path) FilesFacade(io.questdb.std.FilesFacade) Rnd(io.questdb.std.Rnd) MemoryMARW(io.questdb.cairo.vm.api.MemoryMARW)

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