Search in sources :

Example 61 with Function

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

the class FunctionParserTest method testImplicitConstantNullSymbol.

@Test
public void testImplicitConstantNullSymbol() 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(null, SymbolTable.VALUE_IS_NULL);
        }
    });
    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 62 with Function

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

the class FunctionParserTest method testByteToShortCast.

@Test
public void testByteToShortCast() throws SqlException {
    functions.add(new AddShortFunctionFactory());
    final GenericRecordMetadata metadata = new GenericRecordMetadata();
    metadata.add(new TableColumnMetadata("a", 1, ColumnType.BYTE));
    metadata.add(new TableColumnMetadata("b", 2, ColumnType.BYTE));
    FunctionParser functionParser = createFunctionParser();
    Function function = parseFunction("a+b", metadata, functionParser);
    Assert.assertEquals(ColumnType.SHORT, function.getType());
    Assert.assertEquals(131, function.getShort(new Record() {

        @Override
        public byte getByte(int col) {
            if (col == 0) {
                return 41;
            }
            return 90;
        }
    }));
}
Also used : Function(io.questdb.cairo.sql.Function) Record(io.questdb.cairo.sql.Record) Test(org.junit.Test)

Example 63 with Function

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

the class EqDoubleFunctionFactoryTest method testRightNaNDate.

@Test
public void testRightNaNDate() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new DateConstant(10000L));
    args.add(new DoubleConstant(Double.NaN));
    IntList argPositions = new IntList();
    argPositions.add(1);
    argPositions.add(2);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
}
Also used : Function(io.questdb.cairo.sql.Function) DoubleConstant(io.questdb.griffin.engine.functions.constants.DoubleConstant) DateConstant(io.questdb.griffin.engine.functions.constants.DateConstant) ObjList(io.questdb.std.ObjList) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 64 with Function

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

the class EqDoubleFunctionFactoryTest method testLeftNaNFloatNaN.

@Test
public void testLeftNaNFloatNaN() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(new FloatConstant(Float.NaN));
    args.add(new DoubleConstant(Double.NaN));
    IntList argPositions = new IntList();
    argPositions.add(1);
    argPositions.add(2);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertTrue(function.getBool(null));
    Assert.assertTrue(function.isConstant());
}
Also used : Function(io.questdb.cairo.sql.Function) DoubleConstant(io.questdb.griffin.engine.functions.constants.DoubleConstant) ObjList(io.questdb.std.ObjList) FloatConstant(io.questdb.griffin.engine.functions.constants.FloatConstant) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 65 with Function

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

the class EqGeoHashGeoHashFunctionFactoryTest method createEqFunctionAndAssert.

private void createEqFunctionAndAssert(boolean isConstant, boolean expectedEq) {
    try {
        Function func = factory.newInstance(-1, args, null, null, null);
        Assert.assertEquals(expectedEq, func.getBool(null));
        Assert.assertEquals(isConstant, func.isConstant());
        if (func instanceof NegatableBooleanFunction) {
            try {
                NegatingFunctionFactory nf = new NegatingFunctionFactory("noteq", factory);
                func = nf.newInstance(-1, args, null, null, null);
                Assert.assertEquals(!expectedEq, func.getBool(null));
            } catch (SqlException e) {
                e.printStackTrace();
                Assert.fail();
            }
        }
    } catch (SqlException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : Function(io.questdb.cairo.sql.Function) SqlException(io.questdb.griffin.SqlException)

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