Search in sources :

Example 1 with PrepareExecutor

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);
    }
}
Also used : PrepareExecutor(io.mycat.calcite.PrepareExecutor) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) Observable(io.reactivex.rxjava3.core.Observable) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) ExecutorProvider(io.mycat.calcite.ExecutorProvider)

Example 2 with PrepareExecutor

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();
        }
    });
}
Also used : PrepareExecutor(io.mycat.calcite.PrepareExecutor) MycatDataContextImpl(io.mycat.runtime.MycatDataContextImpl) Action(io.reactivex.rxjava3.functions.Action) Plan(io.mycat.calcite.spm.Plan) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) XaSqlConnection(cn.mycat.vertx.xa.XaSqlConnection) ExecutorProvider(io.mycat.calcite.ExecutorProvider) SneakyThrows(lombok.SneakyThrows)

Aggregations

MysqlPayloadObject (io.mycat.api.collector.MysqlPayloadObject)2 ExecutorProvider (io.mycat.calcite.ExecutorProvider)2 PrepareExecutor (io.mycat.calcite.PrepareExecutor)2 XaSqlConnection (cn.mycat.vertx.xa.XaSqlConnection)1 Plan (io.mycat.calcite.spm.Plan)1 MycatDataContextImpl (io.mycat.runtime.MycatDataContextImpl)1 Observable (io.reactivex.rxjava3.core.Observable)1 Action (io.reactivex.rxjava3.functions.Action)1 SneakyThrows (lombok.SneakyThrows)1 ArrayBindable (org.apache.calcite.runtime.ArrayBindable)1