use of io.mycat.calcite.PrepareExecutor in project Mycat2 by MyCATApache.
the class ObservablePlanImplementorImpl method executeQuery.
@Override
public Future<Void> executeQuery(Plan plan) {
AsyncMycatDataContextImpl.SqlMycatDataContextImpl sqlMycatDataContext = new AsyncMycatDataContextImpl.SqlMycatDataContextImpl(context, plan.getCodeExecuterContext(), drdsSqlWithParams);
ExecutorProvider executorProvider = MetaClusterCurrent.wrapper(ExecutorProvider.class);
PrepareExecutor prepare = executorProvider.prepare(plan);
if (context.isVector()) {
PrepareExecutor.ArrowObservable observable1 = prepare.asObservableVector(sqlMycatDataContext, plan.getMetaData());
return response.sendVectorResultSet(observable1.getMycatRowMetaData(), observable1.getObservable());
} else {
ArrayBindable arrayBindable = prepare.getArrayBindable();
Observable<MysqlPayloadObject> observable1 = PrepareExecutor.getMysqlPayloadObjectObservable(arrayBindable, sqlMycatDataContext, plan.getMetaData());
Observable observable = mapToTimeoutObservable(observable1, drdsSqlWithParams);
String parameterizedSQL = drdsSqlWithParams.getParameterizedSQL();
Future<Void> take = TimeRateLimiterService.STRING_INSTANCE.take(parameterizedSQL);
Observable<MysqlPayloadObject> executor = observable;
return response.sendResultSet(executor);
}
}
use of io.mycat.calcite.PrepareExecutor in project Mycat2 by MyCATApache.
the class SqlResultSetService method loadResultSet.
@SneakyThrows
private Optional<Observable<MysqlPayloadObject>> loadResultSet(SQLSelectStatement sqlSelectStatement) {
return cache.get(sqlSelectStatement.toString(), () -> {
if (!MetaClusterCurrent.exist(DrdsSqlCompiler.class)) {
return Optional.empty();
}
MycatDataContext context = new MycatDataContextImpl();
try {
DrdsSqlWithParams drdsSql = DrdsRunnerHelper.preParse(sqlSelectStatement, context.getDefaultSchema());
Plan plan = DrdsRunnerHelper.getPlan(drdsSql);
XaSqlConnection transactionSession = (XaSqlConnection) context.getTransactionSession();
AsyncMycatDataContextImpl.SqlMycatDataContextImpl sqlMycatDataContext = new AsyncMycatDataContextImpl.SqlMycatDataContextImpl(context, plan.getCodeExecuterContext(), drdsSql);
PrepareExecutor prepare = MetaClusterCurrent.wrapper(ExecutorProvider.class).prepare(plan);
Observable<MysqlPayloadObject> observable = prepare.getMysqlPayloadObjectObservable(prepare.getArrayBindable(), sqlMycatDataContext, plan.getMetaData());
observable = observable.doOnTerminate(new Action() {
@Override
public void run() throws Throwable {
transactionSession.closeStatementState().onComplete(event -> context.close());
}
});
List<MysqlPayloadObject> mysqlPayloadObjects = observable.toList().blockingGet();
observable = Observable.fromIterable(mysqlPayloadObjects);
return Optional.ofNullable(observable);
} catch (Throwable t) {
context.kill();
log.error("", t);
return Optional.empty();
}
});
}
Aggregations