Search in sources :

Example 1 with SessionVariableFunction

use of io.ordinate.engine.function.bind.SessionVariableFunction in project Mycat2 by MyCATApache.

the class RexConverter method convertToFunction.

public Function convertToFunction(RexCall call, List<Function> aeOperands) {
    final Function ae;
    SqlKind kind = call.op.kind;
    String lowerName = kind.lowerName;
    switch(call.op.kind) {
        // Conjunction
        case AND:
            ae = executeCompiler.call(lowerName, aeOperands);
            break;
        case OR:
            if (aeOperands.size() == 2) {
                // Binary OR
                ae = executeCompiler.call(lowerName, aeOperands);
            } else {
                // COMPARE_IN
                ae = executeCompiler.call("in", aeOperands);
            }
            break;
        // Binary Comparison
        case EQUALS:
            ae = executeCompiler.call("=", aeOperands);
            break;
        case NOT_EQUALS:
            ae = executeCompiler.call("!=", aeOperands);
            break;
        case LESS_THAN:
            ae = executeCompiler.call("<", aeOperands);
            break;
        case GREATER_THAN:
            ae = executeCompiler.call(">", aeOperands);
            break;
        case LESS_THAN_OR_EQUAL:
            ae = executeCompiler.call("<=", aeOperands);
            break;
        case GREATER_THAN_OR_EQUAL:
            ae = executeCompiler.call(">=", aeOperands);
            break;
        case LIKE:
            ae = executeCompiler.call("like", aeOperands);
            break;
        // Arthimetic Operators
        case PLUS:
            // todo datetime
            ae = executeCompiler.call("+", aeOperands);
            break;
        case MINUS:
            // todo datetime
            // Check for DATETIME - INTERVAL expression first
            // For whatever reason Calcite treats + and - DATETIME operation differently
            ae = executeCompiler.call("-", aeOperands);
            break;
        case TIMES:
            ae = executeCompiler.call("*", aeOperands);
            break;
        case DIVIDE:
            ae = executeCompiler.call("/", aeOperands);
            break;
        case CAST:
            InnerType targetType = convertColumnType(call.getType());
            ae = executeCompiler.cast(aeOperands.get(0), targetType);
            break;
        case NOT:
            ae = executeCompiler.call("not", aeOperands.get(0));
            break;
        case IS_NULL:
            ae = executeCompiler.call("isNull", aeOperands.get(0));
            break;
        case IS_NOT_NULL:
            ae = executeCompiler.call("isNotNull", aeOperands.get(0));
            break;
        case EXISTS:
            ae = executeCompiler.call("exists", aeOperands.get(0));
            break;
        case CASE:
            ae = executeCompiler.call("case", aeOperands);
            break;
        case COALESCE:
            ae = executeCompiler.call("coalesce", aeOperands);
            break;
        case OTHER:
        case OTHER_FUNCTION:
        default:
            String callName = call.op.getName().toUpperCase();
            if (callName.contains("SESSIONVALUE")) {
                Function function = aeOperands.get(0);
                StringFunction stringFunction = (StringFunction) function;
                String name = stringFunction.getString(null).toString();
                SessionVariableFunction sessionVariableFunction = ExecuteCompiler.newSessionVariable(name);
                sessionVariableFunctionMap.add(sessionVariableFunction);
                ae = sessionVariableFunction;
            } else {
                ae = executeCompiler.call(callName, aeOperands);
                if (ae == null) {
                    throw new IllegalArgumentException("Unsupported Calcite expression type! " + call.op.kind.toString());
                }
                if (ae instanceof SessionVariable) {
                    sessionVariableFunctionMap.add((SessionVariable) ae);
                }
            }
    }
    Objects.requireNonNull(ae);
    return ae;
}
Also used : SessionVariableFunction(io.ordinate.engine.function.bind.SessionVariableFunction) ExtractFunction(io.mycat.calcite.sqlfunction.datefunction.ExtractFunction) VariableParameterFunction(io.ordinate.engine.function.bind.VariableParameterFunction) StringFunction(io.ordinate.engine.function.StringFunction) Function(io.ordinate.engine.function.Function) IndexedParameterLinkFunction(io.ordinate.engine.function.bind.IndexedParameterLinkFunction) SessionVariableFunction(io.ordinate.engine.function.bind.SessionVariableFunction) StringFunction(io.ordinate.engine.function.StringFunction) InnerType(io.ordinate.engine.schema.InnerType) NlsString(org.apache.calcite.util.NlsString) SessionVariable(io.ordinate.engine.function.bind.SessionVariable) SqlKind(org.apache.calcite.sql.SqlKind)

Aggregations

ExtractFunction (io.mycat.calcite.sqlfunction.datefunction.ExtractFunction)1 Function (io.ordinate.engine.function.Function)1 StringFunction (io.ordinate.engine.function.StringFunction)1 IndexedParameterLinkFunction (io.ordinate.engine.function.bind.IndexedParameterLinkFunction)1 SessionVariable (io.ordinate.engine.function.bind.SessionVariable)1 SessionVariableFunction (io.ordinate.engine.function.bind.SessionVariableFunction)1 VariableParameterFunction (io.ordinate.engine.function.bind.VariableParameterFunction)1 InnerType (io.ordinate.engine.schema.InnerType)1 SqlKind (org.apache.calcite.sql.SqlKind)1 NlsString (org.apache.calcite.util.NlsString)1