Search in sources :

Example 46 with Function

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

Example 47 with Function

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);
}
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 48 with Function

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));
}
Also used : Function(io.questdb.cairo.sql.Function) SysdateFunctionFactory(io.questdb.griffin.engine.functions.date.SysdateFunctionFactory) ToStrDateFunctionFactory(io.questdb.griffin.engine.functions.date.ToStrDateFunctionFactory) NumericException(io.questdb.std.NumericException) MillisecondClock(io.questdb.std.datetime.millitime.MillisecondClock) Test(org.junit.Test)

Example 49 with Function

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);
}
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 50 with 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));
}
Also used : Function(io.questdb.cairo.sql.Function) InStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InStrFunctionFactory) Record(io.questdb.cairo.sql.Record) 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