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);
}
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());
}
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;
}
Aggregations