use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class FunctionParserTest method testVarArgFunction.
@Test
public void testVarArgFunction() throws SqlException {
functions.add(new InStrFunctionFactory());
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("a", 1, ColumnType.STRING));
FunctionParser functionParser = createFunctionParser();
Record record = new Record() {
@Override
public CharSequence getStr(int col) {
return "YZ";
}
};
Function function = parseFunction("a in ('XY', 'YZ')", metadata, functionParser);
Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
Assert.assertTrue(function.getBool(record));
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class FunctionParserTest method testImplicitConstantStr.
@Test
public void testImplicitConstantStr() throws SqlException {
functions.add(new FunctionFactory() {
@Override
public String getSignature() {
return "x()";
}
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration1, SqlExecutionContext sqlExecutionContext) {
return new StrFunction() {
private final String x = "abc";
@Override
public CharSequence getStr(Record rec) {
return x;
}
@Override
public CharSequence getStrB(Record rec) {
return x;
}
@Override
public boolean isConstant() {
return true;
}
};
}
});
Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
Assert.assertTrue(function instanceof StrConstant);
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class FunctionParserTest method testImplicitConstantDate.
@Test
public void testImplicitConstantDate() throws SqlException {
functions.add(new FunctionFactory() {
@Override
public String getSignature() {
return "x()";
}
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration1, SqlExecutionContext sqlExecutionContext) {
return new DateFunction() {
@Override
public long getDate(Record rec) {
return 0;
}
@Override
public boolean isConstant() {
return true;
}
};
}
});
Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
Assert.assertTrue(function instanceof DateConstant);
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class O3CommitLagTest method insertUncommitted.
private void insertUncommitted(SqlCompiler compiler, SqlExecutionContext sqlExecutionContext, String sql, TableWriter writer) throws SqlException {
minTimestamp = Long.MAX_VALUE;
maxTimestamp = Long.MIN_VALUE;
try (RecordCursorFactory factory = compiler.compile(sql, sqlExecutionContext).getRecordCursorFactory()) {
RecordMetadata metadata = factory.getMetadata();
int timestampIndex = writer.getMetadata().getTimestampIndex();
EntityColumnFilter toColumnFilter = new EntityColumnFilter();
toColumnFilter.of(metadata.getColumnCount());
if (null == copier) {
copier = SqlCompiler.assembleRecordToRowCopier(new BytecodeAssembler(), metadata, writer.getMetadata(), toColumnFilter);
}
try (RecordCursor cursor = factory.getCursor(sqlExecutionContext)) {
final Record record = cursor.getRecord();
while (cursor.hasNext()) {
long timestamp = record.getTimestamp(timestampIndex);
if (timestamp > maxTimestamp) {
maxTimestamp = timestamp;
}
if (timestamp < minTimestamp) {
minTimestamp = timestamp;
}
Row row = writer.newRow(timestamp);
copier.copy(record, row);
row.append();
}
}
}
}
use of io.questdb.cairo.sql.Record in project questdb by bluestreak01.
the class KeyedAggregationTest method testIntSymbolSumAddKeyTimeRange.
@Test
public void testIntSymbolSumAddKeyTimeRange() throws Exception {
assertMemoryLeak(() -> {
compiler.compile("create table tab as (select rnd_symbol('s1','s2','s3', null) s1, rnd_double(2) val, timestamp_sequence(0, 1000000) t from long_sequence(1000000)) timestamp(t) partition by DAY", sqlExecutionContext);
compiler.compile("alter table tab add column s2 symbol cache", sqlExecutionContext);
compiler.compile("insert into tab select rnd_symbol('s1','s2','s3', null), rnd_double(2), timestamp_sequence(cast('1970-01-13T00:00:00.000000Z' as timestamp), 1000000), rnd_symbol('a1','a2','a3', null) s2 from long_sequence(1000000)", sqlExecutionContext);
// test with key falling within null columns
try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-04T12:01' and t < '1970-01-07T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
Record[] expected = new Record[] { new Record() {
@Override
public CharSequence getSym(int col) {
return null;
}
@Override
public double getDouble(int col) {
return 106413.99769604905;
}
} };
assertCursorRawRecords(expected, factory, false, true);
}
// / test key on overlap
try (RecordCursorFactory factory = compiler.compile("select s2, sum(val) from tab where t >= '1970-01-12T12:01' and t < '1970-01-14T11:00' order by s2", sqlExecutionContext).getRecordCursorFactory()) {
Record[] expected = new Record[] { new Record() {
@Override
public CharSequence getSym(int col) {
return null;
}
@Override
public double getDouble(int col) {
return 15636.977658744854;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a1";
}
@Override
public double getDouble(int col) {
return 13073.816187889399;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a2";
}
@Override
public double getDouble(int col) {
return 13240.269899560482;
}
}, new Record() {
@Override
public CharSequence getSym(int col) {
return "a3";
}
@Override
public double getDouble(int col) {
return 13223.021189180576;
}
} };
assertCursorRawRecords(expected, factory, false, true);
}
});
}
Aggregations