Search in sources :

Example 1 with ExprVectorExpression

use of io.ordinate.engine.vector.ExprVectorExpression 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);
}
Also used : CountDistinctDoubleColumnAggregateFunction(io.ordinate.engine.function.aggregate.count.CountDistinctDoubleColumnAggregateFunction) CountColumnAggregateFunction(io.ordinate.engine.function.aggregate.count.CountColumnAggregateFunction) CountDistinctLongColumnAggregateFunction(io.ordinate.engine.function.aggregate.count.CountDistinctLongColumnAggregateFunction) AvgAggregateFunction(io.ordinate.engine.function.aggregate.avg.AvgAggregateFunction) AccumulatorFunction(io.ordinate.engine.function.aggregate.AccumulatorFunction) ExprVectorExpression(io.ordinate.engine.vector.ExprVectorExpression) Schema(org.apache.arrow.vector.types.pojo.Schema) ArrowType(org.apache.arrow.vector.types.pojo.ArrowType) ExprVectorExpression(io.ordinate.engine.vector.ExprVectorExpression) VectorExpression(io.ordinate.engine.vector.VectorExpression)

Example 2 with ExprVectorExpression

use of io.ordinate.engine.vector.ExprVectorExpression 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

ExprVectorExpression (io.ordinate.engine.vector.ExprVectorExpression)2 VectorExpression (io.ordinate.engine.vector.VectorExpression)2 ArrowType (org.apache.arrow.vector.types.pojo.ArrowType)2 AccumulatorFunction (io.ordinate.engine.function.aggregate.AccumulatorFunction)1 AvgAggregateFunction (io.ordinate.engine.function.aggregate.avg.AvgAggregateFunction)1 CountColumnAggregateFunction (io.ordinate.engine.function.aggregate.count.CountColumnAggregateFunction)1 CountDistinctDoubleColumnAggregateFunction (io.ordinate.engine.function.aggregate.count.CountDistinctDoubleColumnAggregateFunction)1 CountDistinctLongColumnAggregateFunction (io.ordinate.engine.function.aggregate.count.CountDistinctLongColumnAggregateFunction)1 ColumnFunction (io.ordinate.engine.function.column.ColumnFunction)1 VectorContext (io.ordinate.engine.vector.VectorContext)1 FieldVector (org.apache.arrow.vector.FieldVector)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1