use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testImplicitConstantSymbol.
@Test
public void testImplicitConstantSymbol() 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 SymbolConstant("xyz", 0);
}
});
Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
Assert.assertTrue(function instanceof SymbolConstant);
}
use of io.questdb.cairo.sql.Function 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.Function in project questdb by bluestreak01.
the class FunctionParserTest method assertBindVariableTypes.
private void assertBindVariableTypes(String expr, FunctionFactory factory, CharSequence expectedFunctionClass, int... expectedTypes) throws SqlException {
bindVariableService.clear();
functions.add(factory);
try (Function f = parseFunction(expr, null, createFunctionParser())) {
TestUtils.assertContains(f.getClass().getCanonicalName(), expectedFunctionClass);
}
for (int i = 0, n = expectedTypes.length; i < n; i++) {
final int expected = expectedTypes[i];
if (expected > -1) {
final int actual = bindVariableService.getFunction(i).getType();
if (expected != actual) {
Assert.fail("type mismatch [expected=" + ColumnType.nameOf(expected) + ", actual=" + ColumnType.nameOf(actual) + ", i=" + i + "]");
}
}
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method assertCastToDouble.
private void assertCastToDouble(double expected, int type1, int type2, Record record) throws SqlException {
functions.add(new AddDoubleFunctionFactory());
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("a", 1, type1));
metadata.add(new TableColumnMetadata("b", 2, type2));
FunctionParser functionParser = createFunctionParser();
Function function = parseFunction("a+b", metadata, functionParser);
Assert.assertEquals(ColumnType.DOUBLE, function.getType());
Assert.assertEquals(expected, function.getDouble(record), 0.00001);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method assertCastToFloat.
private void assertCastToFloat(Record record) throws SqlException {
functions.add(new AddFloatFunctionFactory());
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("a", 1, ColumnType.BYTE));
metadata.add(new TableColumnMetadata("b", 2, ColumnType.SHORT));
FunctionParser functionParser = createFunctionParser();
Function function = parseFunction("a+b", metadata, functionParser);
Assert.assertEquals(ColumnType.FLOAT, function.getType());
Assert.assertEquals((float) 33, function.getFloat(record), 0.00001);
}
Aggregations