Search in sources :

Example 1 with LengthStrFunctionFactory

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));
}
Also used : Function(io.questdb.cairo.sql.Function) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) Record(io.questdb.cairo.sql.Record) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) Test(org.junit.Test)

Aggregations

Function (io.questdb.cairo.sql.Function)1 Record (io.questdb.cairo.sql.Record)1 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)1 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)1 Test (org.junit.Test)1