use of io.questdb.std.IntList 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.std.IntList in project questdb by bluestreak01.
the class EqTimestampStrFunctionFactoryTest method testFalseWhenVariableStringIsNotValidTimestamp.
@Test
public void testFalseWhenVariableStringIsNotValidTimestamp() throws SqlException, NumericException {
long timestamp = parseUTCTimestamp("2020-12-31T23:59:59.000000Z");
CharSequence invalidTimestamp = "abc";
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(TimestampColumn.newInstance(0));
args.add(StrColumn.newInstance(5));
IntList argPositions = new IntList();
argPositions.add(0);
argPositions.add(1);
Function function = factory.newInstance(3, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(new Record() {
@Override
public CharSequence getStr(int col) {
return invalidTimestamp;
}
@Override
public long getTimestamp(int col) {
return timestamp;
}
}));
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testLeftNaNTimestamp.
@Test
public void testLeftNaNTimestamp() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(DoubleConstant.NULL);
args.add(new TimestampConstant(20000L));
IntList argPositions = new IntList();
argPositions.add(2);
argPositions.add(1);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(null));
Assert.assertTrue(function.isConstant());
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testRightNaNTimestamp.
@Test
public void testRightNaNTimestamp() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new TimestampConstant(20000L));
args.add(DoubleConstant.NULL);
IntList argPositions = new IntList();
argPositions.add(1);
argPositions.add(2);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(null));
}
use of io.questdb.std.IntList in project questdb by bluestreak01.
the class EqDoubleFunctionFactoryTest method testRightNaNFloat.
@Test
public void testRightNaNFloat() throws SqlException {
FunctionFactory factory = getFunctionFactory();
ObjList<Function> args = new ObjList<>();
args.add(new DoubleConstant(Double.NaN));
args.add(new FloatConstant(5.1f) {
@Override
public boolean isConstant() {
return false;
}
});
IntList argPositions = new IntList();
argPositions.add(2);
argPositions.add(1);
Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
Assert.assertFalse(function.getBool(null));
Assert.assertFalse(function.isConstant());
}
Aggregations