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());
}
}
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);
}
}
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));
}
}
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()));
}
}
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));
}
}
}
}
});
}
Aggregations