Search in sources :

Example 1 with IndexedParameterLinkFunction

use of io.ordinate.engine.function.bind.IndexedParameterLinkFunction in project Mycat2 by MyCATApache.

the class RexConverter method visitDynamicParam.

public Function visitDynamicParam(RexDynamicParam inputParam) {
    IndexedParameterLinkFunction indexedParameterLinkFunction = executeCompiler.newIndexVariable(inputParam.getIndex(), convertColumnType(inputParam.getType()));
    indexedParameterLinkFunctionMap.put(indexedParameterLinkFunction.getVariableIndex(), indexedParameterLinkFunction);
    return indexedParameterLinkFunction.getBase();
}
Also used : IndexedParameterLinkFunction(io.ordinate.engine.function.bind.IndexedParameterLinkFunction)

Example 2 with IndexedParameterLinkFunction

use of io.ordinate.engine.function.bind.IndexedParameterLinkFunction 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;
}
Also used : ResultSetBuilder(io.mycat.beans.mycat.ResultSetBuilder) SneakyThrows(lombok.SneakyThrows) NewMycatDataContext(org.apache.calcite.runtime.NewMycatDataContext) LoggerFactory(org.slf4j.LoggerFactory) SessionVariable(io.ordinate.engine.function.bind.SessionVariable) CalciteCompiler(io.ordinate.engine.builder.CalciteCompiler) Utilities(org.apache.calcite.runtime.Utilities) Observable(io.reactivex.rxjava3.core.Observable) DrdsSqlWithParams(io.mycat.DrdsSqlWithParams) Map(java.util.Map) RowBaseIterator(io.mycat.api.collector.RowBaseIterator) EnumerableInterpretable(org.apache.calcite.adapter.enumerable.EnumerableInterpretable) CalciteSystemProperty(org.apache.calcite.config.CalciteSystemProperty) IClassBodyEvaluator(org.codehaus.commons.compiler.IClassBodyEvaluator) FieldVector(org.apache.arrow.vector.FieldVector) Logger(org.slf4j.Logger) PhysicalPlan(io.ordinate.engine.physicalplan.PhysicalPlan) io.mycat.calcite(io.mycat.calcite) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) RexConverter(io.ordinate.engine.builder.RexConverter) Enumerable(org.apache.calcite.linq4j.Enumerable) BindVariable(io.ordinate.engine.function.bind.BindVariable) RootContext(io.ordinate.engine.record.RootContext) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) List(java.util.List) AsyncMycatDataContextImpl(io.mycat.AsyncMycatDataContextImpl) CompilerFactoryFactory(org.codehaus.commons.compiler.CompilerFactoryFactory) StringReader(java.io.StringReader) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) IndexedParameterLinkFunction(io.ordinate.engine.function.bind.IndexedParameterLinkFunction) MycatDataContext(io.mycat.MycatDataContext) NotNull(org.jetbrains.annotations.NotNull) ICompilerFactory(org.codehaus.commons.compiler.ICompilerFactory) Plan(io.mycat.calcite.spm.Plan) PhysicalPlan(io.ordinate.engine.physicalplan.PhysicalPlan) CalciteCompiler(io.ordinate.engine.builder.CalciteCompiler) AsyncMycatDataContextImpl(io.mycat.AsyncMycatDataContextImpl) SessionVariable(io.ordinate.engine.function.bind.SessionVariable) Observable(io.reactivex.rxjava3.core.Observable) DrdsSqlWithParams(io.mycat.DrdsSqlWithParams) RootContext(io.ordinate.engine.record.RootContext) RexConverter(io.ordinate.engine.builder.RexConverter) List(java.util.List) MysqlPayloadObject(io.mycat.api.collector.MysqlPayloadObject) BindVariable(io.ordinate.engine.function.bind.BindVariable) Map(java.util.Map) IndexedParameterLinkFunction(io.ordinate.engine.function.bind.IndexedParameterLinkFunction)

Aggregations

IndexedParameterLinkFunction (io.ordinate.engine.function.bind.IndexedParameterLinkFunction)2 AsyncMycatDataContextImpl (io.mycat.AsyncMycatDataContextImpl)1 DrdsSqlWithParams (io.mycat.DrdsSqlWithParams)1 MycatDataContext (io.mycat.MycatDataContext)1 MysqlPayloadObject (io.mycat.api.collector.MysqlPayloadObject)1 RowBaseIterator (io.mycat.api.collector.RowBaseIterator)1 ResultSetBuilder (io.mycat.beans.mycat.ResultSetBuilder)1 io.mycat.calcite (io.mycat.calcite)1 Plan (io.mycat.calcite.spm.Plan)1 CalciteCompiler (io.ordinate.engine.builder.CalciteCompiler)1 RexConverter (io.ordinate.engine.builder.RexConverter)1 BindVariable (io.ordinate.engine.function.bind.BindVariable)1 SessionVariable (io.ordinate.engine.function.bind.SessionVariable)1 PhysicalPlan (io.ordinate.engine.physicalplan.PhysicalPlan)1 RootContext (io.ordinate.engine.record.RootContext)1 Observable (io.reactivex.rxjava3.core.Observable)1 StringReader (java.io.StringReader)1 List (java.util.List)1 Map (java.util.Map)1 SneakyThrows (lombok.SneakyThrows)1