use of io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory in project questdb by bluestreak01.
the class FunctionParserTest method testSymbolFunction.
@Test
public void testSymbolFunction() throws SqlException {
functions.add(new LengthStrFunctionFactory());
functions.add(new LengthSymbolFunctionFactory());
functions.add(new SubIntFunctionFactory());
FunctionParser functionParser = createFunctionParser();
final GenericRecordMetadata metadata = new GenericRecordMetadata();
metadata.add(new TableColumnMetadata("a", 1, ColumnType.STRING));
metadata.add(new TableColumnMetadata("b", 2, ColumnType.SYMBOL, false, 0, false, null));
Function function = parseFunction("length(b) - length(a)", metadata, functionParser);
Record record = new Record() {
@Override
public CharSequence getStr(int col) {
return "ABC";
}
@Override
public int getStrLen(int col) {
return getStr(col).length();
}
@Override
public CharSequence getSym(int col) {
return "EFGHT";
}
};
Assert.assertEquals(2, function.getInt(record));
Function function1 = parseFunction("length(null)", metadata, functionParser);
Assert.assertEquals(-1, function1.getInt(record));
Function function2 = parseFunction("length(NULL)", metadata, functionParser);
Assert.assertEquals(-1, function2.getInt(record));
}
Aggregations