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;
}
Aggregations