Search in sources :

Example 56 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class FunctionParserTest method testImplicitConstantDate.

@Test
public void testImplicitConstantDate() 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 DateFunction() {

                @Override
                public long getDate(Record rec) {
                    return 0;
                }

                @Override
                public boolean isConstant() {
                    return true;
                }
            };
        }
    });
    Function function = parseFunction("x()", new GenericRecordMetadata(), createFunctionParser());
    Assert.assertTrue(function instanceof DateConstant);
}
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 57 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class FunctionParserTest method assertSignatureFailure.

private void assertSignatureFailure(String signature) throws SqlException {
    functions.add(new OrFunctionFactory());
    functions.add(new FunctionFactory() {

        @Override
        public String getSignature() {
            return signature;
        }

        @Override
        public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
            return null;
        }
    });
    functions.add(new NotFunctionFactory());
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.BOOLEAN));
    metadata.add(new TableColumnMetadata("b", 2, ColumnType.BOOLEAN));
    FunctionParser functionParser = createFunctionParser();
    Assert.assertNotNull(parseFunction("a or not b", metadata, functionParser));
    Assert.assertEquals(2, functionParser.getFunctionCount());
}
Also used : OrFunctionFactory(io.questdb.griffin.engine.functions.bool.OrFunctionFactory) IntList(io.questdb.std.IntList) 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) NotFunctionFactory(io.questdb.griffin.engine.functions.bool.NotFunctionFactory)

Example 58 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class FunctionParserTest method testUndefinedBindVariableDefineCursor.

@Test
public void testUndefinedBindVariableDefineCursor() {
    bindVariableService.clear();
    functions.add(new CursorDereferenceFunctionFactory());
    try (Function ignored = parseFunction("($1).n", null, createFunctionParser())) {
        Assert.fail();
    } catch (SqlException e) {
        Assert.assertEquals(1, e.getPosition());
    }
}
Also used : Function(io.questdb.cairo.sql.Function) CursorDereferenceFunctionFactory(io.questdb.griffin.engine.functions.catalogue.CursorDereferenceFunctionFactory) Test(org.junit.Test)

Example 59 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class FunctionParserCastFunctionsNullTest method testCastNullGeoShortBits.

@Test
public void testCastNullGeoShortBits() throws SqlException {
    Function function = parseFunction("cast(null as GeOhAsH(8b))", metadata, functionParser);
    Assert.assertTrue(function.isConstant());
    Assert.assertEquals(ColumnType.GEOSHORT, function.getType());
    Assert.assertEquals(GeoHashes.NULL, function.getGeoShort(null));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 60 with Function

use of io.questdb.cairo.sql.Function in project questdb by bluestreak01.

the class FunctionParserCastFunctionsNullTest method testCastNullGeoLongBits.

@Test
public void testCastNullGeoLongBits() throws SqlException {
    Function function = parseFunction("cast(null as GeOhAsH(60b))", metadata, functionParser);
    Assert.assertTrue(function.isConstant());
    Assert.assertEquals(ColumnType.GEOLONG, function.getType());
    Assert.assertEquals(GeoHashes.NULL, function.getGeoLong(null));
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

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