Search in sources :

Example 1 with AggregateVectorExpression

use of io.ordinate.engine.vector.AggregateVectorExpression in project Mycat2 by MyCATApache.

the class SumLongAggregateFunction method toAggregateVectorExpression.

@Override
public AggregateVectorExpression toAggregateVectorExpression() {
    return new AggregateVectorExpression() {

        @Override
        public long computeFinalLongValue(MapValue resultValue) {
            return resultValue.getLong(stackIndex);
        }

        @Override
        public void computeUpdateValue(MapValue resultValue, FieldVector input) {
            long value = 0;
            BigIntVector bigIntVector = (BigIntVector) input;
            int valueCount = bigIntVector.getValueCount();
            int nullCount = bigIntVector.getNullCount();
            if (nullCount == 0) {
                for (int i = 0; i < valueCount; i++) {
                    value += bigIntVector.get(i);
                }
            } else {
                for (int i = 0; i < valueCount; i++) {
                    if (!bigIntVector.isNull(i)) {
                        value += bigIntVector.get(i);
                    }
                }
            }
            resultValue.addLong(stackIndex, value);
        }

        @Override
        public InnerType getType() {
            return SumLongAggregateFunction.this.getType();
        }

        @Override
        public int getInputColumnIndex() {
            return columnIndex;
        }
    };
}
Also used : AggregateVectorExpression(io.ordinate.engine.vector.AggregateVectorExpression) FieldVector(org.apache.arrow.vector.FieldVector) MapValue(io.questdb.cairo.map.MapValue) BigIntVector(org.apache.arrow.vector.BigIntVector)

Example 2 with AggregateVectorExpression

use of io.ordinate.engine.vector.AggregateVectorExpression in project Mycat2 by MyCATApache.

the class NoKeysAggPlan method createAggContext.

private AggContext createAggContext(RootContext rootContext) {
    int columnCount = schema().getFields().size();
    int length = aggregateExprs.length;
    AggContext aggContext = new AggContext() {

        SimpleMapValue simpleMapValue;

        AggregateVectorExpression[] aggregateVectorExpressions = new AggregateVectorExpression[aggregateExprs.length];

        @Override
        public void initContext() {
            int columnCount = aggregateExprs.length;
            int longSize = RecordUtil.getContextSize(aggregateExprs);
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                aggregateVectorExpressions[columnIndex] = aggregateExprs[columnIndex].toAggregateVectorExpression();
            }
            simpleMapValue = new SimpleMapValue(longSize);
        }

        @Override
        public AggContext reduce(VectorSchemaRoot root) {
            int columnCount = aggregateExprs.length;
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                AggregateVectorExpression aggregateExpr = aggregateVectorExpressions[columnIndex];
                int inputColumnIndex = aggregateExpr.getInputColumnIndex();
                FieldVector inputVector = root.getVector(inputColumnIndex);
                InnerType type = aggregateExpr.getType();
                switch(type) {
                    case BOOLEAN_TYPE:
                    case INT8_TYPE:
                    case INT16_TYPE:
                    case CHAR_TYPE:
                    case INT32_TYPE:
                    case INT64_TYPE:
                        aggregateExpr.computeUpdateValue(simpleMapValue, inputVector);
                        break;
                    case FLOAT_TYPE:
                        break;
                    case DOUBLE_TYPE:
                        aggregateExpr.computeUpdateValue(simpleMapValue, inputVector);
                        break;
                    case STRING_TYPE:
                        break;
                    case BINARY_TYPE:
                        break;
                    case UINT8_TYPE:
                        break;
                    case UINT16_TYPE:
                        break;
                    case UINT32_TYPE:
                        break;
                    case UINT64_TYPE:
                        break;
                    case TIME_MILLI_TYPE:
                        break;
                    case DATE_TYPE:
                        break;
                    case DATETIME_MILLI_TYPE:
                        break;
                    case SYMBOL_TYPE:
                        break;
                    case OBJECT_TYPE:
                        break;
                    case NULL_TYPE:
                        break;
                }
            }
            return this;
        }

        @Override
        public VectorSchemaRoot finalToVectorSchemaRoot() {
            Schema schema = schema();
            VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema, 1);
            output.setRowCount(1);
            int columnCount = aggregateExprs.length;
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                AggregateVectorExpression aggregateExpr = aggregateVectorExpressions[columnIndex];
                InnerType type = aggregateExpr.getType();
                switch(type) {
                    case BOOLEAN_TYPE:
                    case INT8_TYPE:
                    case INT16_TYPE:
                    case CHAR_TYPE:
                    case INT32_TYPE:
                    case INT64_TYPE:
                        {
                            ((BigIntVector) output.getVector(columnIndex)).set(0, aggregateExpr.computeFinalLongValue(simpleMapValue));
                            break;
                        }
                    case FLOAT_TYPE:
                        break;
                    case DOUBLE_TYPE:
                        {
                            ((Float8Vector) output.getVector(columnIndex)).set(0, aggregateExpr.computeFinalDoubleValue(simpleMapValue));
                            break;
                        }
                    case STRING_TYPE:
                        break;
                    case BINARY_TYPE:
                        break;
                    case UINT8_TYPE:
                        break;
                    case UINT16_TYPE:
                        break;
                    case UINT32_TYPE:
                        break;
                    case UINT64_TYPE:
                        break;
                    case TIME_MILLI_TYPE:
                        break;
                    case DATE_TYPE:
                        break;
                    case DATETIME_MILLI_TYPE:
                        break;
                    case SYMBOL_TYPE:
                        break;
                    case OBJECT_TYPE:
                        break;
                    case NULL_TYPE:
                        break;
                }
            }
            return output;
        }
    };
    aggContext.initContext();
    return aggContext;
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) AggregateVectorExpression(io.ordinate.engine.vector.AggregateVectorExpression) SimpleMapValue(io.questdb.griffin.engine.groupby.SimpleMapValue) Schema(org.apache.arrow.vector.types.pojo.Schema) FieldVector(org.apache.arrow.vector.FieldVector) InnerType(io.ordinate.engine.schema.InnerType)

Aggregations

AggregateVectorExpression (io.ordinate.engine.vector.AggregateVectorExpression)2 FieldVector (org.apache.arrow.vector.FieldVector)2 InnerType (io.ordinate.engine.schema.InnerType)1 MapValue (io.questdb.cairo.map.MapValue)1 SimpleMapValue (io.questdb.griffin.engine.groupby.SimpleMapValue)1 BigIntVector (org.apache.arrow.vector.BigIntVector)1 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)1 Schema (org.apache.arrow.vector.types.pojo.Schema)1