use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class LastGeoHashGroupByFunctionFactory method newInstance.
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
Function function = args.getQuick(0);
int type = function.getType();
// Reuse first implementation overriding computeNext() method inline
switch(ColumnType.tagOf(type)) {
case ColumnType.GEOBYTE:
return new FirstGeoHashGroupByFunctionByte(type, function) {
@Override
public void computeNext(MapValue mapValue, Record record) {
mapValue.putByte(this.valueIndex, this.function.getGeoByte(record));
}
};
case ColumnType.GEOSHORT:
return new FirstGeoHashGroupByFunctionShort(type, function) {
@Override
public void computeNext(MapValue mapValue, Record record) {
mapValue.putShort(this.valueIndex, this.function.getGeoShort(record));
}
};
case ColumnType.GEOINT:
return new FirstGeoHashGroupByFunctionInt(type, function) {
@Override
public void computeNext(MapValue mapValue, Record record) {
mapValue.putInt(this.valueIndex, this.function.getGeoInt(record));
}
};
default:
return new FirstGeoHashGroupByFunctionLong(type, function) {
@Override
public void computeNext(MapValue mapValue, Record record) {
mapValue.putLong(this.valueIndex, this.function.getGeoLong(record));
}
};
}
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class IntersectRecordCursor method populateSlaveMap.
private void populateSlaveMap(RecordCursor cursor) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
MapKey key = map.withKey();
key.put(record, recordSink);
key.createValue();
interruptor.checkInterrupted();
}
}
use of io.questdb.cairo.sql.Record 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));
}
}
}
}
use of io.questdb.cairo.sql.Record 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));
}
}
}
});
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class MinCharGroupByFunctionFactoryTest method testAllNull.
@Test
public void testAllNull() throws SqlException {
compiler.compile("create table tab (f char)", sqlExecutionContext);
try (TableWriter w = engine.getWriter(sqlExecutionContext.getCairoSecurityContext(), "tab", "testing")) {
for (int i = 100; i > 10; i--) {
TableWriter.Row r = w.newRow();
r.append();
}
w.commit();
}
try (RecordCursorFactory factory = compiler.compile("select min(f) from tab", sqlExecutionContext).getRecordCursorFactory()) {
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
Record record = cursor.getRecord();
Assert.assertEquals(1, cursor.size());
Assert.assertTrue(cursor.hasNext());
Assert.assertEquals(0, record.getChar(0));
}
}
}
Aggregations