Search in sources :

Example 51 with Function

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);
}
Also used : Function(io.questdb.cairo.sql.Function) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) EqLongFunctionFactory(io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) SwitchFunctionFactory(io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory) EqIntFunctionFactory(io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) EqDoubleFunctionFactory(io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) ToCharBinFunctionFactory(io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory) CastStrToGeoHashFunctionFactory(io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test)

Example 52 with Function

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);
}
Also used : IntList(io.questdb.std.IntList) Function(io.questdb.cairo.sql.Function) Record(io.questdb.cairo.sql.Record) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) EqLongFunctionFactory(io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) SwitchFunctionFactory(io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory) EqIntFunctionFactory(io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory) LengthSymbolFunctionFactory(io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory) OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) LengthStrFunctionFactory(io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory) EqDoubleFunctionFactory(io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) ToStrTimestampFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory) ToCharBinFunctionFactory(io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory) CastStrToGeoHashFunctionFactory(io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory) Test(org.junit.Test)

Example 53 with Function

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 + "]");
            }
        }
    }
}
Also used : Function(io.questdb.cairo.sql.Function)

Example 54 with Function

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);
}
Also used : Function(io.questdb.cairo.sql.Function)

Example 55 with Function

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);
}
Also used : Function(io.questdb.cairo.sql.Function)

Aggregations

Function (io.questdb.cairo.sql.Function)204 Test (org.junit.Test)101 UnaryFunction (io.questdb.griffin.engine.functions.UnaryFunction)39 IntList (io.questdb.std.IntList)33 Record (io.questdb.cairo.sql.Record)28 ToStrTimestampFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrTimestampFunctionFactory)28 ToStrDateFunctionFactory (io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory)27 NotFunctionFactory (io.questdb.griffin.engine.functions.bool.NotFunctionFactory)26 InStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InStrFunctionFactory)25 EqDoubleFunctionFactory (io.questdb.griffin.engine.functions.eq.EqDoubleFunctionFactory)25 EqIntFunctionFactory (io.questdb.griffin.engine.functions.eq.EqIntFunctionFactory)25 EqLongFunctionFactory (io.questdb.griffin.engine.functions.eq.EqLongFunctionFactory)25 OrFunctionFactory (io.questdb.griffin.engine.functions.bool.OrFunctionFactory)24 CastStrToGeoHashFunctionFactory (io.questdb.griffin.engine.functions.cast.CastStrToGeoHashFunctionFactory)23 CursorDereferenceFunctionFactory (io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory)23 SysdateFunctionFactory (io.questdb.griffin.engine.functions.date.SysdateFunctionFactory)23 LengthStrFunctionFactory (io.questdb.griffin.engine.functions.str.LengthStrFunctionFactory)23 LengthSymbolFunctionFactory (io.questdb.griffin.engine.functions.str.LengthSymbolFunctionFactory)23 ToCharBinFunctionFactory (io.questdb.griffin.engine.functions.str.ToCharBinFunctionFactory)23 SwitchFunctionFactory (io.questdb.griffin.engine.functions.conditional.SwitchFunctionFactory)22