Search in sources :

Example 76 with Function

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

the class EqDoubleFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) {
    // this is probably a special case factory
    // NaN is always a double, so this could lead comparisons of all primitive types
    // to NaN route to this factory. Obviously comparing naively will not work
    // We have to check arg types and when NaN is present we would generate special case
    // functions for NaN checks.
    Function left = args.getQuick(0);
    Function right = args.getQuick(1);
    if (left.isConstant() && ColumnType.isDouble(left.getType()) && Double.isNaN(left.getDouble(null))) {
        switch(ColumnType.tagOf(right.getType())) {
            case ColumnType.INT:
                return new FuncIntIsNaN(right);
            case ColumnType.LONG:
                return new FuncLongIsNaN(right);
            case ColumnType.DATE:
                return new FuncDateIsNaN(right);
            case ColumnType.TIMESTAMP:
                return new FuncTimestampIsNaN(right);
            case ColumnType.FLOAT:
                return new FuncFloatIsNaN(right);
            default:
                // double
                return new FuncDoubleIsNaN(right);
        }
    } else if (right.isConstant() && ColumnType.isDouble(right.getType()) && Double.isNaN(right.getDouble(null))) {
        switch(ColumnType.tagOf(left.getType())) {
            case ColumnType.INT:
                return new FuncIntIsNaN(left);
            case ColumnType.LONG:
                return new FuncLongIsNaN(left);
            case ColumnType.DATE:
                return new FuncDateIsNaN(left);
            case ColumnType.TIMESTAMP:
                return new FuncTimestampIsNaN(left);
            case ColumnType.FLOAT:
                return new FuncFloatIsNaN(left);
            default:
                // double
                return new FuncDoubleIsNaN(left);
        }
    }
    return new Func(args.getQuick(0), args.getQuick(1));
}
Also used : BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) Function(io.questdb.cairo.sql.Function) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) NegatableBooleanFunction(io.questdb.griffin.engine.functions.NegatableBooleanFunction)

Example 77 with Function

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

the class EqSymCharFunctionFactory 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
    SymbolFunction symFunc = (SymbolFunction) args.getQuick(0);
    Function chrFunc = args.getQuick(1);
    if (chrFunc.isConstant()) {
        final char constValue = chrFunc.getChar(null);
        if (symFunc.getStaticSymbolTable() != null) {
            return new ConstCheckColumnFunc(symFunc, constValue);
        } else {
            return new ConstCheckFunc(symFunc, constValue);
        }
    }
    return new Func(symFunc, chrFunc);
}
Also used : SymbolFunction(io.questdb.griffin.engine.functions.SymbolFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) BinaryFunction(io.questdb.griffin.engine.functions.BinaryFunction) Function(io.questdb.cairo.sql.Function) NegatableBooleanFunction(io.questdb.griffin.engine.functions.NegatableBooleanFunction) SymbolFunction(io.questdb.griffin.engine.functions.SymbolFunction)

Example 78 with Function

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

the class NotMatchStrFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function value = args.getQuick(0);
    CharSequence regex = args.getQuick(1).getStr(null);
    if (regex == null) {
        throw SqlException.$(argPositions.getQuick(1), "NULL regex");
    }
    try {
        Matcher matcher = Pattern.compile(Chars.toString(regex)).matcher("");
        return new MatchFunction(value, matcher);
    } catch (PatternSyntaxException e) {
        throw SqlException.$(argPositions.getQuick(1) + e.getIndex() + 1, e.getMessage());
    }
}
Also used : UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) BooleanFunction(io.questdb.griffin.engine.functions.BooleanFunction) Matcher(java.util.regex.Matcher) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 79 with Function

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

the class LongSequenceFunctionFactory method newInstance.

@Override
public Function newInstance(int position, ObjList<Function> args, IntList argPositions, CairoConfiguration configuration, SqlExecutionContext sqlExecutionContext) throws SqlException {
    Function countFunc;
    final Function seedLoFunc;
    final Function seedHiFunc;
    if (args != null) {
        final int argCount = args.size();
        if (argCount == 1 && SqlCompiler.isAssignableFrom(ColumnType.LONG, (countFunc = args.getQuick(0)).getType())) {
            return new CursorFunction(new LongSequenceCursorFactory(METADATA, countFunc.getLong(null)));
        }
        if (argCount > 2 && SqlCompiler.isAssignableFrom(ColumnType.LONG, (countFunc = args.getQuick(0)).getType()) && SqlCompiler.isAssignableFrom(ColumnType.LONG, (seedLoFunc = args.getQuick(1)).getType()) && SqlCompiler.isAssignableFrom(ColumnType.LONG, (seedHiFunc = args.getQuick(2)).getType())) {
            return new CursorFunction(new SeedingLongSequenceCursorFactory(METADATA, countFunc.getLong(null), seedLoFunc.getLong(null), seedHiFunc.getLong(null)));
        }
    }
    throw SqlException.position(position).put("invalid arguments");
}
Also used : CursorFunction(io.questdb.griffin.engine.functions.CursorFunction) Function(io.questdb.cairo.sql.Function) CursorFunction(io.questdb.griffin.engine.functions.CursorFunction)

Example 80 with Function

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

the class AbstractLikeStrFunctionFactory 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);
    final Function pattern = args.getQuick(1);
    if (pattern.isConstant()) {
        final CharSequence likeString = pattern.getStr(null);
        if (likeString != null && likeString.length() > 0) {
            String p = escapeSpecialChars(likeString, null);
            assert p != null;
            return new ConstLikeStrFunction(value, Pattern.compile(p, Pattern.DOTALL).matcher(""));
        }
        return BooleanConstant.FALSE;
    }
    if (pattern instanceof IndexedParameterLinkFunction) {
        // bind variable
        return new BindLikeStrFunction(value, pattern);
    }
    throw SqlException.$(argPositions.getQuick(1), "use constant or bind variable");
}
Also used : IndexedParameterLinkFunction(io.questdb.griffin.engine.functions.bind.IndexedParameterLinkFunction) UnaryFunction(io.questdb.griffin.engine.functions.UnaryFunction) Function(io.questdb.cairo.sql.Function) BooleanFunction(io.questdb.griffin.engine.functions.BooleanFunction) IndexedParameterLinkFunction(io.questdb.griffin.engine.functions.bind.IndexedParameterLinkFunction)

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