Search in sources :

Example 86 with Record

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

the class FastMapTest method populateMap.

private void populateMap(FastMap 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 87 with Record

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

the class FastMapTest method assertCursorLong256.

private void assertCursorLong256(Rnd rnd, RecordCursor cursor, Long256Impl long256) {
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        long256.fromRnd(rnd);
        Long256 long256a = record.getLong256A(1);
        Long256 long256b = record.getLong256B(1);
        Assert.assertEquals(long256a.getLong0(), long256.getLong0());
        Assert.assertEquals(long256a.getLong1(), long256.getLong1());
        Assert.assertEquals(long256a.getLong2(), long256.getLong2());
        Assert.assertEquals(long256a.getLong3(), long256.getLong3());
        Assert.assertEquals(long256b.getLong0(), long256.getLong0());
        Assert.assertEquals(long256b.getLong1(), long256.getLong1());
        Assert.assertEquals(long256b.getLong2(), long256.getLong2());
        Assert.assertEquals(long256b.getLong3(), long256.getLong3());
        Assert.assertEquals(rnd.nextChar(), record.getChar(2));
        // value part, it comes first in record
        Assert.assertEquals(rnd.nextDouble(), record.getDouble(0), 0.000000001d);
    }
}
Also used : Record(io.questdb.cairo.sql.Record)

Example 88 with Record

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

the class FastMapTest method assertCursor1.

private void assertCursor1(Rnd rnd, RecordCursor cursor) {
    final Record record = cursor.getRecord();
    while (cursor.hasNext()) {
        int col = 9;
        Assert.assertEquals(rnd.nextByte(), record.getByte(col++));
        Assert.assertEquals(rnd.nextShort(), record.getShort(col++));
        Assert.assertEquals(rnd.nextInt(), record.getInt(col++));
        Assert.assertEquals(rnd.nextLong(), record.getLong(col++));
        Assert.assertEquals(rnd.nextFloat(), record.getFloat(col++), 0.000000001f);
        Assert.assertEquals(rnd.nextDouble(), record.getDouble(col++), 0.000000001d);
        if ((rnd.nextPositiveInt() % 4) == 0) {
            Assert.assertNull(record.getStr(col));
            Assert.assertEquals(-1, record.getStrLen(col++));
        } else {
            CharSequence expected = rnd.nextChars(rnd.nextPositiveInt() % 16);
            TestUtils.assertEquals(expected, record.getStr(col++));
        }
        Assert.assertEquals(rnd.nextBoolean(), record.getBool(col++));
        Assert.assertEquals(rnd.nextLong(), record.getDate(col++));
        Assert.assertEquals(rnd.nextShort(), record.getShort(col));
        // value part, it comes first in record
        col = 0;
        Assert.assertEquals(rnd.nextByte(), record.getByte(col++));
        Assert.assertEquals(rnd.nextShort(), record.getShort(col++));
        Assert.assertEquals(rnd.nextInt(), record.getInt(col++));
        Assert.assertEquals(rnd.nextLong(), record.getLong(col++));
        Assert.assertEquals(rnd.nextFloat(), record.getFloat(col++), 0.000000001f);
        Assert.assertEquals(rnd.nextDouble(), record.getDouble(col++), 0.000000001d);
        Assert.assertEquals(rnd.nextBoolean(), record.getBool(col++));
        Assert.assertEquals(rnd.nextLong(), record.getDate(col++));
        Assert.assertEquals(rnd.nextInt(), record.getInt(col));
    }
}
Also used : Record(io.questdb.cairo.sql.Record)

Example 89 with Record

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

the class FastMapTest method populateMapGeo.

private void populateMapGeo(Map 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 90 with Record

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

the class FastMapTest method testGeohashRecordAsKey.

@Test
public void testGeohashRecordAsKey() throws Exception {
    TestUtils.assertMemoryLeak(() -> {
        final int N = 5000;
        final Rnd rnd = new Rnd();
        int precisionBits = 10;
        int geohashType = ColumnType.getGeoHashTypeWithBits(precisionBits);
        BytecodeAssembler asm = new BytecodeAssembler();
        try (TableModel model = new TableModel(configuration, "x", PartitionBy.NONE)) {
            model.col("a", ColumnType.LONG).col("b", geohashType);
            CairoTestUtils.create(model);
        }
        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 (FastMap map = new FastMap(Numbers.SIZE_1MB, new SymbolAsStrTypes(reader.getMetadata()), new ArrayColumnTypes().add(ColumnType.LONG).add(ColumnType.INT).add(ColumnType.SHORT).add(ColumnType.BYTE).add(ColumnType.FLOAT).add(ColumnType.DOUBLE).add(ColumnType.DATE).add(ColumnType.TIMESTAMP).add(ColumnType.BOOLEAN), N, 0.9f, 1)) {
                RecordSink sink = RecordSinkFactory.getInstance(asm, reader.getMetadata(), entityColumnFilter, true);
                // this random will be populating values
                Rnd rnd2 = new Rnd();
                RecordCursor cursor = reader.getCursor();
                populateMap(map, rnd2, cursor, sink);
                try (RecordCursor mapCursor = map.getCursor()) {
                    long c = 0;
                    rnd.reset();
                    rnd2.reset();
                    final Record record = mapCursor.getRecord();
                    while (mapCursor.hasNext()) {
                        // value
                        Assert.assertEquals(++c, record.getLong(0));
                        Assert.assertEquals(rnd2.nextInt(), record.getInt(1));
                        Assert.assertEquals(rnd2.nextShort(), record.getShort(2));
                        Assert.assertEquals(rnd2.nextByte(), record.getByte(3));
                        Assert.assertEquals(rnd2.nextFloat(), record.getFloat(4), 0.000001f);
                        Assert.assertEquals(rnd2.nextDouble(), record.getDouble(5), 0.000000001);
                        Assert.assertEquals(rnd2.nextLong(), record.getDate(6));
                        Assert.assertEquals(rnd2.nextLong(), record.getTimestamp(7));
                        Assert.assertEquals(rnd2.nextBoolean(), record.getBool(8));
                    }
                }
            }
        }
    });
}
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