Search in sources :

Example 71 with Function

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

the class CastShortToSymbolFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    final Function arg = args.getQuick(0);
    if (arg.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(arg.getShort(null));
        return SymbolConstant.newInstance(sink);
    }
    return new Func(arg);
}
Also used : Function(io.questdb.cairo.sql.Function) StringSink(io.questdb.std.str.StringSink)

Example 72 with Function

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

the class CastDateToSymbolFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    final Function arg = args.getQuick(0);
    if (arg.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(arg.getDate(null));
        return SymbolConstant.newInstance(sink);
    }
    return new Func(arg);
}
Also used : SymbolFunction(io.questdb.griffin.engine.functions.SymbolFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StringSink(io.questdb.std.str.StringSink)

Example 73 with Function

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

the class EqStrCharFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    // there are optimisation opportunities
    // 1. when one of args is constant null comparison can boil down to checking
    // length of non-constant (must be -1)
    // 2. when one of arguments is constant, save method call and use a field
    Function strFunc = args.getQuick(0);
    Function charFunc = args.getQuick(1);
    if (ColumnType.isNull(strFunc.getType()) || ColumnType.isNull(charFunc.getType())) {
        return new Func(strFunc, charFunc);
    }
    if (strFunc.isConstant() && !charFunc.isConstant()) {
        CharSequence str = strFunc.getStr(null);
        if (str == null || str.length() != 1) {
            return new NegatedAwareBooleanConstantFunc();
        }
        return new ConstStrFunc(charFunc, str.charAt(0));
    }
    if (!strFunc.isConstant() && charFunc.isConstant()) {
        return new ConstChrFunc(strFunc, charFunc.getChar(null));
    }
    if (strFunc.isConstant() && charFunc.isConstant()) {
        return new ConstStrConstChrFunc(Chars.equalsNc(strFunc.getStr(null), charFunc.getChar(null)));
    }
    return new Func(strFunc, charFunc);
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) ConstantFunction(io.questdb.griffin.engine.functions.constants.ConstantFunction) Function(io.questdb.cairo.sql.Function) NegatableBooleanFunction(io.questdb.griffin.engine.functions.NegatableBooleanFunction)

Example 74 with Function

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

the class ToTimestampVCFunctionFactory 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 Func(arg, tlCompiler.get().compile(pattern), configuration.getDefaultDateLocale());
}
Also used : TimestampFunction(io.questdb.griffin.engine.functions.TimestampFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function)

Example 75 with Function

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

the class ToTimezoneTimestampFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function timestamp = args.getQuick(0);
    Function timezone = args.getQuick(1);
    if (timezone.isConstant()) {
        return getTimestampFunction(argPositions, timestamp, timezone, 1);
    } else {
        return new ToTimezoneFunctionVar(timestamp, timezone);
    }
}
Also used : TimestampFunction(io.questdb.griffin.engine.functions.TimestampFunction) BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) ToUTCTimestampFunctionFactory.getTimestampFunction(io.questdb.griffin.engine.functions.date.ToUTCTimestampFunctionFactory.getTimestampFunction) Function(io.questdb.cairo.sql.Function)

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