use of io.ordinate.engine.function.bind.SessionVariable 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;
}
use of io.ordinate.engine.function.bind.SessionVariable in project Mycat2 by MyCATApache.
the class ExecutorProviderImpl method prepare.
@Override
public PrepareExecutor prepare(Plan plan) {
CodeExecuterContext codeExecuterContext = plan.getCodeExecuterContext();
PrepareExecutor bindable = codeExecuterContext.bindable;
if (bindable != null)
return bindable;
try {
return codeExecuterContext.bindable = PrepareExecutor.of((newMycatDataContext, mycatRowMetaData) -> {
DrdsSqlWithParams drdsSql = newMycatDataContext.getDrdsSql();
CalciteCompiler mycatCalciteCompiler = new CalciteCompiler();
PhysicalPlan factory = mycatCalciteCompiler.convert(plan.getMycatRel());
factory = fixCast(factory);
RexConverter rexConverter = mycatCalciteCompiler.getRexConverter();
Map<Integer, IndexedParameterLinkFunction> indexedMap = rexConverter.getIndexedParameterLinkFunctionMap();
List<Object> params = drdsSql.getParams();
if (!indexedMap.isEmpty()) {
for (int i = 0; i < params.size(); i++) {
Object o = params.get(i);
IndexedParameterLinkFunction indexedParameterLinkFunction = indexedMap.get(i);
if (indexedParameterLinkFunction != null) {
BindVariable base = (BindVariable) indexedParameterLinkFunction.getBase();
base.setObject(o);
}
}
}
List<SessionVariable> sessionMap = rexConverter.getSessionVariableFunctionMap();
for (SessionVariable sessionVariable : sessionMap) {
sessionVariable.setSession(newMycatDataContext.getContext());
}
AsyncMycatDataContextImpl.SqlMycatDataContextImpl sqlMycatDataContext = new AsyncMycatDataContextImpl.SqlMycatDataContextImpl(newMycatDataContext.getContext(), plan.getCodeExecuterContext(), drdsSql);
RootContext rootContext = new RootContext(sqlMycatDataContext);
Observable<VectorSchemaRoot> schemaRootObservable = factory.execute(rootContext);
return PrepareExecutor.ArrowObservable.of(mycatRowMetaData, schemaRootObservable);
}, getArrayBindable(codeExecuterContext));
} catch (Exception exception) {
LOGGER.error("", exception);
}
return null;
}
Aggregations