use of io.ordinate.engine.vector.VectorExpression in project Mycat2 by MyCATApache.
the class ExecuteCompiler method project.
public static PhysicalPlan project(PhysicalPlan input, List<Function> exprs) {
ArrowType[] exprTypes = new ArrowType[exprs.size()];
VectorExpression[] expressions = new VectorExpression[exprs.size()];
for (int i = 0; i < exprTypes.length; i++) {
Function function = exprs.get(i);
boolean constant = function.isConstant();
boolean runtimeConstant = function.isRuntimeConstant();
exprTypes[i] = function.getType().getArrowType();
expressions[i] = new ExprVectorExpression(function);
}
Schema schema = SchemaBuilder.ofArrowType(exprTypes).toArrow();
return new ProjectionPlan(input, Arrays.asList(expressions), schema);
}
use of io.ordinate.engine.vector.VectorExpression in project Mycat2 by MyCATApache.
the class ProjectionPlan method execute.
@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
FieldVector[] vectorList = new FieldVector[schema().getFields().size()];
return input.execute(rootContext).subscribeOn(Schedulers.computation()).map(input -> {
try {
int index = 0;
for (VectorExpression expr : exprs) {
int finalIndex = index;
if (expr.isColumn()) {
ExprVectorExpression exprVectorExpression = (ExprVectorExpression) expr;
ColumnFunction columnFunction = (ColumnFunction) exprVectorExpression.getFunction();
FieldVector vector = input.getVector(columnFunction.getColumnIndex());
vectorList[finalIndex] = vector;
} else {
ArrowType type = expr.getType();
vectorList[finalIndex] = FieldBuilder.of("", type, expr.isNullable()).toArrow().createVector(rootContext.getRootAllocator());
vectorList[finalIndex].setInitialCapacity(input.getRowCount());
vectorList[finalIndex].allocateNew();
VectorContext vContext1 = new VectorContext() {
@Override
public VectorSchemaRoot getVectorSchemaRoot() {
return input;
}
@Override
public FieldVector getOutputVector() {
return vectorList[finalIndex];
}
@Override
public int getRowCount() {
return input.getRowCount();
}
};
expr.eval(vContext1);
vectorList[index] = (vContext1.getOutputVector());
vContext1.free();
}
index++;
}
VectorSchemaRoot res = VectorSchemaRoot.of(vectorList);
res.setRowCount(input.getRowCount());
return res;
} finally {
ProjectionPlan.this.input.eachFree(input);
}
});
}
Aggregations