Search in sources :

Example 1 with PhysicalPlan

use of io.ordinate.engine.physicalplan.PhysicalPlan in project Mycat2 by MyCATApache.

the class CsvScanTest method baseTest.

// @Test
@SneakyThrows
public void baseTest() {
    Path path = Paths.get("D:\\testcsv.csv");
    // 
    // CsvWriter writer = new CsvWriter(path.toFile(), new CsvWriterSettings());
    // for (int i = 0; i < 800_0000; i++) {
    // writer.writeRow(Arrays.asList(i,i));
    // }
    // writer.close();
    StopWatch stopWatch = new StopWatch();
    ExecuteCompiler executeCompiler = new ExecuteCompiler();
    CsvScanPlan csvScan = new ValuesCsvScanPlan(path.toString(), SchemaBuilder.ofArrowType(ArrowTypes.INT64_TYPE, ArrowTypes.STRING_TYPE).toArrow(), executeCompiler.createRootContext());
    Function column = executeCompiler.column(0, csvScan.schema());
    Function add = executeCompiler.call("+", Arrays.asList(column, column));
    RootContext rootContext = executeCompiler.createRootContext();
    PhysicalPlan projection = executeCompiler.project(csvScan, Arrays.asList(add));
    for (int i = 0; i < 100; i++) {
        stopWatch.reset();
        stopWatch.start();
        Observable<VectorSchemaRoot> execute = projection.execute(rootContext);
        AtomicLong count = new AtomicLong(0);
        execute.blockingLatest().forEach(c -> {
            count.getAndAdd(c.getRowCount());
            c.close();
        });
        stopWatch.stop();
        System.out.println("count:" + count);
        Duration duration = Duration.ofMillis(stopWatch.getTime());
        System.out.println(duration.getSeconds());
        System.out.println(stopWatch.toString());
    }
// 
// Thread.sleep(100000000);
}
Also used : Path(java.nio.file.Path) ValuesCsvScanPlan(io.ordinate.engine.physicalplan.ValuesCsvScanPlan) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) PhysicalPlan(io.ordinate.engine.physicalplan.PhysicalPlan) ValuesCsvScanPlan(io.ordinate.engine.physicalplan.ValuesCsvScanPlan) CsvScanPlan(io.ordinate.engine.physicalplan.CsvScanPlan) Duration(java.time.Duration) StopWatch(org.apache.commons.lang3.time.StopWatch) RootContext(io.ordinate.engine.record.RootContext) Function(io.ordinate.engine.function.Function) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExecuteCompiler(io.ordinate.engine.builder.ExecuteCompiler) SneakyThrows(lombok.SneakyThrows)

Example 2 with PhysicalPlan

use of io.ordinate.engine.physicalplan.PhysicalPlan in project Mycat2 by MyCATApache.

the class ProjectFactory method create.

@Override
public PhysicalPlan create(ComplierContext context) {
    PhysicalPlan physicalPlan = inputFactory.create(context);
    ImmutableList.Builder<Function> builder = ImmutableList.builder();
    for (RexNode project : mycatRel.getProjects()) {
        Function function = context.convertRex(project);
        builder.add(function);
    }
    return ExecuteCompiler.project(physicalPlan, builder.build());
}
Also used : Function(io.ordinate.engine.function.Function) PhysicalPlan(io.ordinate.engine.physicalplan.PhysicalPlan) ImmutableList(com.google.common.collect.ImmutableList) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with PhysicalPlan

use of io.ordinate.engine.physicalplan.PhysicalPlan 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

PhysicalPlan (io.ordinate.engine.physicalplan.PhysicalPlan)3 Function (io.ordinate.engine.function.Function)2 RootContext (io.ordinate.engine.record.RootContext)2 SneakyThrows (lombok.SneakyThrows)2 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)2 ImmutableList (com.google.common.collect.ImmutableList)1 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 ExecuteCompiler (io.ordinate.engine.builder.ExecuteCompiler)1 RexConverter (io.ordinate.engine.builder.RexConverter)1 BindVariable (io.ordinate.engine.function.bind.BindVariable)1 IndexedParameterLinkFunction (io.ordinate.engine.function.bind.IndexedParameterLinkFunction)1 SessionVariable (io.ordinate.engine.function.bind.SessionVariable)1