use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method assertGeoConstFunctionTypeAndValue.
private void assertGeoConstFunctionTypeAndValue(FunctionFactory factory, CharSequence expectedFunctionClass, int expectedType, int expectedValue) throws SqlException {
bindVariableService.clear();
functions.add(factory);
try (Function f = parseFunction("geohash_func()", null, createFunctionParser())) {
TestUtils.assertContains(f.getClass().getCanonicalName(), expectedFunctionClass);
Assert.assertEquals(expectedType, f.getType());
switch(ColumnType.tagOf(expectedType)) {
case ColumnType.GEOBYTE:
Assert.assertEquals(expectedValue, f.getGeoByte(null));
break;
case ColumnType.GEOSHORT:
Assert.assertEquals(expectedValue, f.getGeoShort(null));
break;
case ColumnType.GEOINT:
Assert.assertEquals(expectedValue, f.getGeoInt(null));
break;
default:
Assert.assertEquals(expectedValue, f.getGeoLong(null));
break;
}
}
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testFunctionFactoryNullFunction.
@Test
public void testFunctionFactoryNullFunction() {
functions.add(new FunctionFactory() {
@Override
public String getSignature() {
return "x()";
}
@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
return null;
}
});
final GenericRecordMetadata metadata = new GenericRecordMetadata();
assertFail(0, "bad function factory (NULL), check log", "x()", metadata);
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testNoArgFunction.
@Test
public void testNoArgFunction() throws SqlException {
functions.add(new SysdateFunctionFactory());
functions.add(new ToStrDateFunctionFactory());
FunctionParser functionParser = new FunctionParser(new DefaultCairoConfiguration(root) {
@Override
public MillisecondClock getMillisecondClock() {
return () -> {
try {
return DateFormatUtils.parseUTCDate("2018-03-04T21:40:00.000Z");
} catch (NumericException e) {
Assert.fail();
}
return 0;
};
}
}, new FunctionFactoryCache(configuration, functions));
Function function = parseFunction("to_str(sysdate(), 'EE, dd-MMM-yyyy HH:mm:ss')", new GenericRecordMetadata(), functionParser);
TestUtils.assertEquals("Sunday, 04-Mar-2018 21:40:00", function.getStr(null));
}
use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.
the class FunctionParserTest method testImplicitConstantNull.
@Test
public void testImplicitConstantNull() 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() {
@Override
public CharSequence getStr(Record rec) {
return null;
}
@Override
public CharSequence getStrB(Record rec) {
return null;
}
@Override
public boolean isConstant() {
return true;
}
};
}
});
Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
Assert.assertSame(StrConstant.NULL, function);
}
use of io.questdb.cairo.sql.Function 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));
}
Aggregations