Search in sources :

Example 91 with Record

use of io.questdb.cairo.sql.Record 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 92 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class CompactMapTest method populateMap.

private void populateMap(CompactMap map, Rnd rnd2, RecordCursor cursor, RecordSink sink) {
    long counter = 0;
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        MapKey key = map.withKey();
        key.put(record, sink);
        MapValue value = key.createValue();
        Assert.assertTrue(value.isNew());
        value.putLong(0, ++counter);
        value.putInt(1, rnd2.nextInt());
        value.putShort(2, rnd2.nextShort());
        value.putByte(3, rnd2.nextByte());
        value.putFloat(4, rnd2.nextFloat());
        value.putDouble(5, rnd2.nextDouble());
        value.putDate(6, rnd2.nextLong());
        value.putTimestamp(7, rnd2.nextLong());
        value.putBool(8, rnd2.nextBoolean());
    }
}
Also used : Record(io.questdb.cairo.sql.Record)

Example 93 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class CompactMapTest method populateMapGeo.

private void populateMapGeo(CompactMap map, Rnd rnd2, RecordCursor cursor, RecordSink sink) {
    long counter = 0;
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        MapKey key = map.withKey();
        key.put(record, sink);
        MapValue value = key.createValue();
        Assert.assertTrue(value.isNew());
        value.putLong(0, ++counter);
        value.putInt(1, rnd2.nextInt());
        value.putShort(2, rnd2.nextShort());
        value.putByte(3, rnd2.nextByte());
        value.putFloat(4, rnd2.nextFloat());
        value.putDouble(5, rnd2.nextDouble());
        value.putDate(6, rnd2.nextLong());
        value.putTimestamp(7, rnd2.nextLong());
        value.putBool(8, rnd2.nextBoolean());
        value.putByte(9, (byte) Math.abs(rnd2.nextByte()));
        value.putShort(10, (short) Math.abs(rnd2.nextShort()));
        value.putInt(11, Math.abs(rnd2.nextInt()));
        value.putLong(12, Math.abs(rnd2.nextLong()));
    }
}
Also used : Record(io.questdb.cairo.sql.Record)

Example 94 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class CompactMapTest method testGeoHashValueAccess.

@Test
public void testGeoHashValueAccess() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        int precisionBits = 10;
        int geohashType = ColumnType.getGeoHashTypeWithBits(precisionBits);
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE)) {
            model.col("a", ColumnType.LONG).col("b", geohashType);
            CairoTestUtils.create(model);
        }
        BytecodeAssembler asm = new BytecodeAssembler();
        final int N = 1000;
        final Rnd rnd = new Rnd();
        try (TableWriter writer = new TableWriter(configuration, "x")) {
            for (int i = 0; i < N; i++) {
                TableWriter.Row row = writer.newRow();
                long rndGeohash = GeoHashes.fromCoordinatesDeg(rnd.nextDouble() * 180 - 90, rnd.nextDouble() * 360 - 180, precisionBits);
                row.putLong(0, i);
                row.putGeoHash(1, rndGeohash);
                row.append();
            }
            writer.commit();
        }
        try (TableReader reader = new TableReader(configuration, "x")) {
            EntityColumnFilter entityColumnFilter = new EntityColumnFilter();
            entityColumnFilter.of(reader.getMetadata().getColumnCount());
            try (CompactMap map = new CompactMap(1024 * 1024, new SymbolAsStrTypes(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG), N, 0.9, 1, Integer.MAX_VALUE)) {
                RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
                RecordCursor cursor = reader.getCursor();
                long counter = 0;
                final Record record = cursor.getRecord();
                while (cursor.hasNext()) {
                    MapKey key = map.withKey();
                    key.put(record, sink);
                    MapValue value = key.createValue();
                    Assert.assertTrue(value.isNew());
                    value.putLong(0, counter++);
                }
                cursor.toTop();
                int count = 0;
                while (cursor.hasNext()) {
                    MapKey key = map.withKey();
                    key.put(record, sink);
                    MapValue value = key.findValue();
                    Assert.assertNotNull(value);
                    Assert.assertEquals(count++, value.getLong(0));
                }
                Assert.assertEquals(N, count);
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 95 with Record

use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.

the class CompactMapTest method testRowIdAccess.

@Test
public void testRowIdAccess() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        ColumnTypes types = new SingleColumnType(ColumnType.INT);
        final int N = 10000;
        final Rnd rnd = new Rnd();
        try (CompactMap map = new CompactMap(Numbers.SIZE_1MB, types, types, 64, 0.5, 1, Integer.MAX_VALUE)) {
            for (int i = 0; i < N; i++) {
                MapKey key = map.withKey();
                key.putInt(rnd.nextInt());
                MapValue values = key.createValue();
                Assert.assertTrue(values.isNew());
                values.putInt(0, i + 1);
            }
            // reset random generator and iterate map to double the value
            rnd.reset();
            LongList list = new LongList();
            try (RecordCursor mapCursor = map.getCursor()) {
                final MapRecord record = (MapRecord) mapCursor.getRecord();
                while (mapCursor.hasNext()) {
                    list.add(record.getRowId());
                    Assert.assertEquals(rnd.nextInt(), record.getInt(1));
                    MapValue value = record.getValue();
                    value.putInt(0, value.getInt(0) * 2);
                }
                // access map by rowid now
                rnd.reset();
                Record rec = mapCursor.getRecordB();
                for (int i = 0, n = list.size(); i < n; i++) {
                    mapCursor.recordAt(rec, list.getQuick(i));
                    Assert.assertEquals((i + 1) * 2, rec.getInt(0));
                    Assert.assertEquals(rnd.nextInt(), rec.getInt(1));
                }
                rnd.reset();
                Assert.assertNotSame(rec, mapCursor.getRecord());
                for (int i = 0, n = list.size(); i < n; i++) {
                    mapCursor.recordAt(rec, list.getQuick(i));
                    Assert.assertEquals((i + 1) * 2, rec.getInt(0));
                    Assert.assertEquals(rnd.nextInt(), rec.getInt(1));
                }
            }
        }
    });
}
Also used : RecordCursor(io.questdb.cairo.sql.RecordCursor) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Aggregations

Record (io.questdb.cairo.sql.Record)171 Test (org.junit.Test)130 RecordCursor (io.questdb.cairo.sql.RecordCursor)121 RecordCursorFactory (io.questdb.cairo.sql.RecordCursorFactory)79 TableWriter (io.questdb.cairo.TableWriter)70 AbstractGriffinTest (io.questdb.griffin.AbstractGriffinTest)66 Rnd (io.questdb.std.Rnd)32 Function (io.questdb.cairo.sql.Function)28 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)16 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)15 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)15 IntList (io.questdb.std.IntList)15 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)14 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)14 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)14 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)14 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)14 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)14 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)13 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)13