Search in sources :

Example 1 with FunctionFactory

use of io.questdb.griffin.FunctionFactory 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 2 with FunctionFactory

use of io.questdb.griffin.FunctionFactory 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 3 with FunctionFactory

use of io.questdb.griffin.FunctionFactory in project questdb by bluestreak01.

the class CaseCommon method getCastFunction.

static Function getCastFunction(Function arg, int argPosition, int toType, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    if (ColumnType.isNull(arg.getType())) {
        return Constants.getNullConstant(toType);
    }
    final int keyIndex = castFactories.keyIndex(Numbers.encodeLowHighInts(arg.getType(), toType));
    if (keyIndex < 0) {
        FunctionFactory fact = castFactories.valueAt(keyIndex);
        ObjList<Function> args = tlArgs.get();
        args.clear();
        args.add(arg);
        IntList argPositions = tlArgPositions.get();
        argPositions.clear();
        argPositions.add(argPosition);
        return fact.newInstance(0, args, argPositions, configuration, sqlExecutionContext);
    }
    return arg;
}
Also used : Function(io.questdb.cairo.sql.Function) FunctionFactory(io.questdb.griffin.FunctionFactory)

Example 4 with FunctionFactory

use of io.questdb.griffin.FunctionFactory in project questdb by bluestreak01.

the class EqTimestampStrFunctionFactoryTest method testFalseWhenVariableStringIsNotValidTimestamp.

@Test
public void testFalseWhenVariableStringIsNotValidTimestamp() throws SqlException, NumericException {
    long timestamp = parseUTCTimestamp("2020-12-31T23:59:59.000000Z");
    CharSequence invalidTimestamp = "abc";
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(TimestampColumn.newInstance(0));
    args.add(StrColumn.newInstance(5));
    IntList argPositions = new IntList();
    argPositions.add(0);
    argPositions.add(1);
    Function function = factory.newInstance(3, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(new Record() {

        @Override
        public CharSequence getStr(int col) {
            return invalidTimestamp;
        }

        @Override
        public long getTimestamp(int col) {
            return timestamp;
        }
    }));
}
Also used : Function(io.questdb.cairo.sql.Function) ObjList(io.questdb.std.ObjList) Record(io.questdb.cairo.sql.Record) InTimestampStrFunctionFactory(io.questdb.griffin.engine.functions.bool.InTimestampStrFunctionFactory) FunctionFactory(io.questdb.griffin.FunctionFactory) IntList(io.questdb.std.IntList) Test(org.junit.Test) AbstractFunctionFactoryTest(io.questdb.griffin.engine.AbstractFunctionFactoryTest)

Example 5 with FunctionFactory

use of io.questdb.griffin.FunctionFactory in project questdb by bluestreak01.

the class EqDoubleFunctionFactoryTest method testLeftNaNTimestamp.

@Test
public void testLeftNaNTimestamp() throws SqlException {
    FunctionFactory factory = getFunctionFactory();
    ObjList<Function> args = new ObjList<>();
    args.add(DoubleConstant.NULL);
    args.add(new TimestampConstant(20000L));
    IntList argPositions = new IntList();
    argPositions.add(2);
    argPositions.add(1);
    Function function = factory.newInstance(4, args, argPositions, configuration, sqlExecutionContext);
    Assert.assertFalse(function.getBool(null));
    Assert.assertTrue(function.isConstant());
}
Also used : Function(io.questdb.cairo.sql.Function) TimestampConstant(io.questdb.griffin.engine.functions.constants.TimestampConstant) 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)

Aggregations

Function (io.questdb.cairo.sql.Function)11 FunctionFactory (io.questdb.griffin.FunctionFactory)11 AbstractFunctionFactoryTest (io.questdb.griffin.engine.AbstractFunctionFactoryTest)10 IntList (io.questdb.std.IntList)10 ObjList (io.questdb.std.ObjList)10 Test (org.junit.Test)10 DoubleConstant (io.questdb.griffin.engine.functions.constants.DoubleConstant)7 DateConstant (io.questdb.griffin.engine.functions.constants.DateConstant)3 FloatConstant (io.questdb.griffin.engine.functions.constants.FloatConstant)3 TimestampConstant (io.questdb.griffin.engine.functions.constants.TimestampConstant)3 Record (io.questdb.cairo.sql.Record)1 InTimestampStrFunctionFactory (io.questdb.griffin.engine.functions.bool.InTimestampStrFunctionFactory)1