Search in sources :

Example 96 with Function

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

the class TypeOfFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    if (args != null && args.size() == 1) {
        final Function arg = args.getQuick(0);
        final int argType = arg.getType();
        return ColumnType.isNull(argType) ? NULL : TYPE_NAMES.get(arg.getType());
    }
    throw SqlException.$(position, "exactly one argument expected");
}
Also used : Function(io.questdb.cairo.sql.Function)

Example 97 with Function

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

the class NullRecordFactory method getInstance.

public static Record getInstance(ColumnTypes types) {
    final ObjList<Function> functions = new ObjList<>(types.getColumnCount());
    for (int i = 0, n = types.getColumnCount(); i < n; i++) {
        Function function = Constants.getNullConstant(types.getColumnType(i));
        assert function != null;
        functions.add(function);
    }
    return new VirtualRecord(functions);
}
Also used : Function(io.questdb.cairo.sql.Function) ObjList(io.questdb.std.ObjList) VirtualRecord(io.questdb.cairo.sql.VirtualRecord)

Example 98 with Function

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

the class FunctionParserEqFunctionsNullTest method testEqFunctionResolutionNullArgsForNumericTypes.

@Test
public void testEqFunctionResolutionNullArgsForNumericTypes() throws SqlException {
    functions.addAll(Arrays.asList(EQ_FUNCS));
    FunctionParser functionParser = createFunctionParser();
    for (int col0Type : EQUIVALENT_NULL_TYPES) {
        for (int col1Type : EQUIVALENT_NULL_TYPES) {
            final GenericRecordMetadata metadata = new GenericRecordMetadata();
            metadata.add(new TableColumnMetadata("col0", 1, col0Type));
            metadata.add(new TableColumnMetadata("col1", 2, col1Type));
            Collections.shuffle(functions);
            Function function = parseFunction("null = null", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(ILLEGAL_ACCESS_RECORD));
            function = parseFunction("null != null", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertFalse(function.getBool(ILLEGAL_ACCESS_RECORD));
            function = parseFunction("col0 = null", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(NULL_RECORD));
            function = parseFunction("col1 = null", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(NULL_RECORD));
            function = parseFunction("col0 = col0", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(NULL_RECORD));
            function = parseFunction("null = col0", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(NULL_RECORD));
            function = parseFunction("null = col1", metadata, functionParser);
            Assert.assertEquals(ColumnType.BOOLEAN, function.getType());
            Assert.assertTrue(function.getBool(NULL_RECORD));
        }
    }
}
Also used : Function(io.questdb.cairo.sql.Function) Test(org.junit.Test)

Example 99 with Function

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

the class ToDateFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    final Function arg = args.getQuick(0);
    final CharSequence pattern = args.getQuick(1).getStr(null);
    if (pattern == null) {
        throw SqlException.$(argPositions.getQuick(1), "pattern is required");
    }
    return new ToDateFunction(arg, tlCompiler.get().compile(pattern), configuration.getDefaultDateLocale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) DateFunction(io.questdb.griffin.engine.functions.DateFunction)

Example 100 with Function

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

the class ToStrDateFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function fmt = args.getQuick(1);
    CharSequence format = fmt.getStr(null);
    if (format == null) {
        throw SqlException.$(argPositions.getQuick(1), "format must not be null");
    }
    DateFormat dateFormat = tlCompiler.get().compile(fmt.getStr(null));
    Function var = args.getQuick(0);
    if (var.isConstant()) {
        long value = var.getDate(null);
        if (value == Numbers.LONG_NaN) {
            return StrConstant.NULL;
        }
        StringSink sink = tlSink.get();
        sink.clear();
        dateFormat.format(value, configuration.getDefaultDateLocale(), "Z", sink);
        return new StrConstant(sink);
    }
    return new ToCharDateVCFFunc(args.getQuick(0), tlCompiler.get().compile(format), configuration.getDefaultDateLocale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) DateFormat(io.questdb.std.datetime.DateFormat) StringSink(io.questdb.std.str.StringSink) StrConstant(io.questdb.griffin.engine.functions.constants.StrConstant)

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