Search in sources :

Example 1 with ColumnFunction

use of io.ordinate.engine.function.column.ColumnFunction 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);
        }
    });
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) ExprVectorExpression(io.ordinate.engine.vector.ExprVectorExpression) ColumnFunction(io.ordinate.engine.function.column.ColumnFunction) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) VectorContext(io.ordinate.engine.vector.VectorContext) FieldVector(org.apache.arrow.vector.FieldVector) ExprVectorExpression(io.ordinate.engine.vector.ExprVectorExpression) VectorExpression(io.ordinate.engine.vector.VectorExpression)

Aggregations

ColumnFunction (io.ordinate.engine.function.column.ColumnFunction)1 ExprVectorExpression (io.ordinate.engine.vector.ExprVectorExpression)1 VectorContext (io.ordinate.engine.vector.VectorContext)1 VectorExpression (io.ordinate.engine.vector.VectorExpression)1 FieldVector (org.apache.arrow.vector.FieldVector)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 ArrowType (org.apache.arrow.vector.types.pojo.ArrowType)1