Search in sources :

Example 66 with Function

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

the class CoalesceBenchmark method testBaseline.

@Benchmark
public long testBaseline() {
    Function function = new CoalesceFunctionFactory.LongCoalesceFunction(constFunctions, constFunctions.size());
    long sum = 0;
    for (int i = 0; i < N; i++) {
        sum += function.getLong(records[i]);
    }
    return sum;
}
Also used : LongFunction(io.questdb.griffin.engine.functions.LongFunction) Function(io.questdb.cairo.sql.Function)

Example 67 with Function

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

the class CastFloatToSymbolFunctionFactory 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.getFloat(null), 4);
        return SymbolConstant.newInstance(sink);
    }
    return new Func(arg);
}
Also used : Function(io.questdb.cairo.sql.Function) StringSink(io.questdb.std.str.StringSink)

Example 68 with Function

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

the class CastGeoHashToGeoHashFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    final Function value = args.getQuick(0);
    int srcType = value.getType();
    int targetType = args.getQuick(1).getType();
    int srcBitsPrecision = ColumnType.getGeoHashBits(srcType);
    int targetBitsPrecision = ColumnType.getGeoHashBits(targetType);
    int shift = srcBitsPrecision - targetBitsPrecision;
    if (shift > 0) {
        if (value.isConstant()) {
            long val = GeoHashes.getGeoLong(srcType, value, null);
            // >> shift will take care of NULL value -1
            return Constants.getGeoHashConstantWithType(val >> shift, targetType);
        }
        final Function result = castFunc(shift, targetType, value, srcType);
        if (result != null) {
            return result;
        }
    } else if (shift == 0) {
        return value;
    }
    // check if this is a null of different bit count
    if (value.isConstant() && GeoHashes.getGeoLong(value.getType(), value, null) == GeoHashes.NULL) {
        return Constants.getNullConstant(targetType);
    }
    throw SqlException.position(position).put("CAST cannot decrease precision from GEOHASH(").put(srcBitsPrecision).put("b) to GEOHASH(").put(targetBitsPrecision).put("b)");
}
Also used : Function(io.questdb.cairo.sql.Function)

Example 69 with Function

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

the class InSymbolFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    CharSequenceHashSet set = new CharSequenceHashSet();
    int n = args.size();
    if (n == 1) {
        return BooleanConstant.FALSE;
    }
    for (int i = 1; i < n; i++) {
        Function func = args.getQuick(i);
        switch(ColumnType.tagOf(func.getType())) {
            case ColumnType.NULL:
            case ColumnType.STRING:
            case ColumnType.SYMBOL:
                CharSequence value = func.getStr(null);
                if (value == null) {
                    set.add(null);
                } else {
                    set.add(Chars.toString(value));
                }
                break;
            case ColumnType.CHAR:
                set.add(String.valueOf(func.getChar(null)));
                break;
            default:
                throw SqlException.$(argPositions.getQuick(i), "STRING constant expected");
        }
    }
    SymbolFunction var = (SymbolFunction) args.getQuick(0);
    if (var.isConstant()) {
        return BooleanConstant.of(set.contains(var.getSymbol(null)));
    }
    return new Func(var, set);
}
Also used : SymbolFunction(io.questdb.griffin.engine.functions.SymbolFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) BooleanFunction(io.questdb.griffin.engine.functions.BooleanFunction) SymbolFunction(io.questdb.griffin.engine.functions.SymbolFunction)

Example 70 with Function

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

the class CastDoubleToStrFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    Function intFunc = args.getQuick(0);
    if (intFunc.isConstant()) {
        final StringSink sink = Misc.getThreadLocalBuilder();
        sink.put(intFunc.getDouble(null), configuration.getDoubleToStrCastScale());
        return new StrConstant(Chars.toString(sink));
    }
    return new Func(args.getQuick(0), configuration.getDoubleToStrCastScale());
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) StrFunction(io.questdb.griffin.engine.functions.StrFunction) 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