use of io.ordinate.engine.builder.RexConverter 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