Search in sources :

Example 1 with Record

use of io.ordinate.engine.record.Record in project Mycat2 by MyCATApache.

the class HeapTopNPlan method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    Comparator<Record> recordComparator;
    if (physicalSortProperties.size() == 1) {
        recordComparator = physicalSortProperties.get(0).evaluateToSortComparator();
    } else {
        recordComparator = physicalSortProperties.get(0).evaluateToSortComparator();
        for (PhysicalSortProperty physicalSortProperty : physicalSortProperties.subList(1, physicalSortProperties.size())) {
            recordComparator = recordComparator.thenComparing(physicalSortProperty.evaluateToSortComparator());
        }
    }
    OutputLinq4jPhysicalPlan midPlan = OutputLinq4jPhysicalPlan.create(input);
    Observable<Object[]> observable = midPlan.executeToObject(rootContext);
    @NonNull Iterable<Record> objects = MycatRxJavaUtl.blockingIterable(observable.map(i -> RecordImpl.create(i)));
    Enumerable<Record> records = EnumerableDefaults.orderBy(Linq4j.asEnumerable(objects), i -> i, recordComparator, offset.getInt(null), fetch.getInt(null));
    return InputRecordPhysicalPlan.create(schema(), Observable.fromIterable(records)).execute(rootContext);
}
Also used : Schema(org.apache.arrow.vector.types.pojo.Schema) Linq4j(org.apache.calcite.linq4j.Linq4j) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) PhysicalSortProperty(io.ordinate.engine.builder.PhysicalSortProperty) Enumerable(org.apache.calcite.linq4j.Enumerable) MycatRxJavaUtl(io.mycat.MycatRxJavaUtl) NonNull(io.reactivex.rxjava3.annotations.NonNull) RootContext(io.ordinate.engine.record.RootContext) RecordImpl(io.ordinate.engine.record.RecordImpl) Record(io.ordinate.engine.record.Record) List(java.util.List) EnumerableDefaults(org.apache.calcite.linq4j.EnumerableDefaults) Observable(io.reactivex.rxjava3.core.Observable) IntFunction(io.ordinate.engine.function.IntFunction) Comparator(java.util.Comparator) Collections(java.util.Collections) PhysicalSortProperty(io.ordinate.engine.builder.PhysicalSortProperty) NonNull(io.reactivex.rxjava3.annotations.NonNull) Record(io.ordinate.engine.record.Record)

Example 2 with Record

use of io.ordinate.engine.record.Record in project Mycat2 by MyCATApache.

the class InputRecordPhysicalPlan method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    return Observable.create(emitter -> {
        VectorSchemaRoot vectorSchemaRoot = null;
        final int batchSize = rootContext.getBatchSize();
        int batchId = 0;
        for (Record record : MycatRxJavaUtl.blockingIterable(observable)) {
            if (batchId >= batchSize) {
                emitter.onNext(vectorSchemaRoot);
                vectorSchemaRoot = null;
            }
            if (vectorSchemaRoot == null) {
                vectorSchemaRoot = rootContext.getVectorSchemaRoot(schema(), batchSize);
                batchId = 0;
            }
            recordSink.copy(record, batchId, vectorSchemaRoot);
            ++batchId;
        }
    });
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) Record(io.ordinate.engine.record.Record)

Example 3 with Record

use of io.ordinate.engine.record.Record in project Mycat2 by MyCATApache.

the class NLJoinPlan method createRecord.

private Record createRecord(VectorSchemaRoot leftInput, int leftIndex, VectorSchemaRoot rightBatch, int rightIndex) {
    int leftCount = leftInput.getFieldVectors().size();
    IntUnaryOperator function = columnIndex -> {
        if (columnIndex < leftCount) {
            return leftIndex;
        } else {
            return rightIndex;
        }
    };
    return new Record() {

        boolean isNull;

        @Override
        public void setPosition(int value) {
        }

        private int getPosition(int columnIndex) {
            return function.applyAsInt(columnIndex);
        }

        private <T extends FieldVector> T getFieldVector(int columnIndex) {
            FieldVector vector;
            if (columnIndex < leftCount) {
                vector = leftInput.getVector(columnIndex);
            } else {
                vector = rightBatch.getVector(columnIndex - leftCount);
            }
            return (T) vector;
        }

        @Override
        public int getInt(int columnIndex) {
            IntVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public long getLong(int columnIndex) {
            BigIntVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public byte getByte(int columnIndex) {
            TinyIntVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public short getShort(int columnIndex) {
            SmallIntVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public BinarySequence getBinary(int columnIndex) {
            VarBinaryVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return null;
            } else {
                isNull = false;
                return BinarySequence.of(vector.get(position));
            }
        }

        @Override
        public char getChar(int columnIndex) {
            SmallIntVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return (char) vector.get(position);
            }
        }

        @Override
        public long getDate(int columnIndex) {
            DateMilliVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public long getDatetime(int columnIndex) {
            TimeStampVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position) * 1000L;
            }
        }

        @Override
        public CharSequence getString(int columnIndex) {
            VarCharVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return null;
            } else {
                isNull = false;
                return new String(vector.get(position));
            }
        }

        @Override
        public CharSequence getSymbol(int columnIndex) {
            return getString(columnIndex);
        }

        @Override
        public float getFloat(int columnIndex) {
            Float4Vector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public double getDouble(int columnIndex) {
            Float8Vector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public long getTime(int columnIndex) {
            TimeStampVector vector = getFieldVector(columnIndex);
            int position = getPosition(columnIndex);
            if (vector.isNull(position)) {
                isNull = true;
                return 0;
            } else {
                isNull = false;
                return vector.get(position);
            }
        }

        @Override
        public boolean isNull(int columnIndex) {
            return false;
        }

        @Override
        public short getUInt16(int columnIndex) {
            return 0;
        }

        @Override
        public long getUInt64(int columnIndex) {
            return 0;
        }

        @Override
        public Object getObject(int columnIndex) {
            return null;
        }

        @Override
        public int getUInt32(int i) {
            return 0;
        }

        @Override
        public String toString() {
            int columnCount = leftInput.getSchema().getFields().size() + rightBatch.getSchema().getFields().size();
            ArrayList arrayList = new ArrayList();
            for (int columnIndex = 0; columnIndex < columnCount; columnIndex++) {
                FieldVector vector = getFieldVector(columnIndex);
                Object object = vector.getObject(function.applyAsInt(columnIndex));
                arrayList.add(object);
            }
            return arrayList.toString();
        }
    };
}
Also used : Schema(org.apache.arrow.vector.types.pojo.Schema) Logger(org.slf4j.Logger) IntUnaryOperator(java.util.function.IntUnaryOperator) LoggerFactory(org.slf4j.LoggerFactory) Function(io.ordinate.engine.function.Function) RootContext(io.ordinate.engine.record.RootContext) org.apache.arrow.vector(org.apache.arrow.vector) ArrayList(java.util.ArrayList) BinarySequence(io.ordinate.engine.function.BinarySequence) Record(io.ordinate.engine.record.Record) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) JoinType(org.apache.calcite.linq4j.JoinType) Observable(io.reactivex.rxjava3.core.Observable) NotNull(org.jetbrains.annotations.NotNull) ArrayList(java.util.ArrayList) IntUnaryOperator(java.util.function.IntUnaryOperator) Record(io.ordinate.engine.record.Record)

Example 4 with Record

use of io.ordinate.engine.record.Record in project Mycat2 by MyCATApache.

the class IfNullFunctionFactory method newInstance.

@Override
public Function newInstance(List<Function> args, EngineConfiguration configuration) {
    return new Function() {

        Function left;

        Function right;

        boolean isNull;

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

        @Override
        public List<Function> getArgs() {
            return args;
        }

        @Override
        public BinarySequence getBinary(Record rec) {
            isNull = false;
            BinarySequence binary = left.getBinary(rec);
            if (!left.isNull(rec)) {
                return binary;
            }
            binary = right.getBinary(rec);
            if (!right.isNull(rec)) {
                return binary;
            }
            isNull = true;
            return null;
        }

        @Override
        public byte getByte(Record rec) {
            isNull = false;
            byte aByte = left.getByte(rec);
            if (!left.isNull(rec)) {
                return aByte;
            }
            aByte = right.getByte(rec);
            if (!right.isNull(rec)) {
                return aByte;
            }
            isNull = true;
            return 0;
        }

        @Override
        public char getChar(Record rec) {
            isNull = false;
            char aChar = left.getChar(rec);
            if (!left.isNull(rec)) {
                return aChar;
            }
            aChar = right.getChar(rec);
            if (!right.isNull(rec)) {
                return aChar;
            }
            isNull = true;
            return 0;
        }

        @Override
        public long getDate(Record rec) {
            isNull = false;
            long date = left.getDate(rec);
            if (!left.isNull(rec)) {
                return date;
            }
            date = right.getDate(rec);
            if (!right.isNull(rec)) {
                return date;
            }
            isNull = true;
            return 0;
        }

        @Override
        public double getDouble(Record rec) {
            isNull = false;
            double aDouble = left.getDouble(rec);
            if (!left.isNull(rec)) {
                return aDouble;
            }
            aDouble = right.getDouble(rec);
            if (!right.isNull(rec)) {
                return aDouble;
            }
            isNull = true;
            return 0;
        }

        @Override
        public float getFloat(Record rec) {
            isNull = false;
            float aFloat = left.getFloat(rec);
            if (!left.isNull(rec)) {
                return aFloat;
            }
            aFloat = right.getFloat(rec);
            if (!right.isNull(rec)) {
                return aFloat;
            }
            isNull = true;
            return 0;
        }

        @Override
        public int getInt(Record rec) {
            isNull = false;
            int anInt = left.getInt(rec);
            if (!left.isNull(rec)) {
                return anInt;
            }
            anInt = right.getInt(rec);
            if (!right.isNull(rec)) {
                return anInt;
            }
            isNull = true;
            return 0;
        }

        @Override
        public long getLong(Record rec) {
            isNull = false;
            long aLong = left.getLong(rec);
            if (!left.isNull(rec)) {
                return aLong;
            }
            aLong = right.getLong(rec);
            if (!right.isNull(rec)) {
                return aLong;
            }
            isNull = true;
            return 0;
        }

        @Override
        public short getShort(Record rec) {
            isNull = false;
            short aLong = left.getShort(rec);
            if (!left.isNull(rec)) {
                return aLong;
            }
            aLong = right.getShort(rec);
            if (!right.isNull(rec)) {
                return aLong;
            }
            isNull = true;
            return 0;
        }

        @Override
        public CharSequence getString(Record rec) {
            isNull = false;
            CharSequence charSequence = left.getString(rec);
            if (!left.isNull(rec)) {
                return charSequence;
            }
            charSequence = right.getString(rec);
            if (!right.isNull(rec)) {
                return charSequence;
            }
            isNull = true;
            return null;
        }

        @Override
        public long getDatetime(Record rec) {
            isNull = false;
            long datetime = left.getDatetime(rec);
            if (!left.isNull(rec)) {
                return datetime;
            }
            datetime = right.getDatetime(rec);
            if (!right.isNull(rec)) {
                return datetime;
            }
            isNull = true;
            return 0;
        }

        @Override
        public long getTime(Record rec) {
            isNull = false;
            long time = left.getTime(rec);
            if (!left.isNull(rec)) {
                return time;
            }
            time = right.getTime(rec);
            if (!right.isNull(rec)) {
                return time;
            }
            isNull = true;
            return 0;
        }

        @Override
        public CharSequence getSymbol(Record rec) {
            isNull = false;
            CharSequence symbol = left.getSymbol(rec);
            if (!left.isNull(rec)) {
                return symbol;
            }
            symbol = right.getSymbol(rec);
            if (!right.isNull(rec)) {
                return symbol;
            }
            isNull = true;
            return null;
        }

        @Override
        public boolean isNull(Record rec) {
            return isNull;
        }
    };
}
Also used : Function(io.ordinate.engine.function.Function) BinarySequence(io.ordinate.engine.function.BinarySequence) Record(io.ordinate.engine.record.Record)

Example 5 with Record

use of io.ordinate.engine.record.Record in project Mycat2 by MyCATApache.

the class ExprVectorExpression method eval.

@Override
public void eval(VectorContext ctx) {
    FieldVector outputVector = ctx.getOutputVector();
    int nullCount = outputVector.getNullCount();
    int rowCount = ctx.getRowCount();
    boolean nullable = function.isNullableConstant();
    Record record = function.generateSink(ctx);
    switch(function.getType()) {
        case BOOLEAN_TYPE:
            {
                BitVector bitVector = (BitVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        int value = function.getInt(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            bitVector.setNull(i);
                        } else {
                            bitVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        int bool = function.getInt(record);
                        bitVector.set(i, bool);
                    }
                }
                break;
            }
        case INT8_TYPE:
            break;
        case INT16_TYPE:
            break;
        case INT32_TYPE:
            {
                IntVector valueVector = (IntVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        int value = function.getInt(record);
                        if (function.isNull(record)) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        int value = function.getInt(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case INT64_TYPE:
            {
                BigIntVector valueVector = (BigIntVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getLong(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getLong(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case FLOAT_TYPE:
            {
                Float4Vector valueVector = (Float4Vector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        float value = function.getFloat(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        float value = function.getFloat(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case DOUBLE_TYPE:
            {
                Float8Vector valueVector = (Float8Vector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        double value = function.getDouble(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        double value = function.getDouble(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case STRING_TYPE:
            {
                VarCharVector valueVector = (VarCharVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        CharSequence value = function.getString(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.setSafe(i, (value.toString().getBytes()));
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        CharSequence value = function.getString(record);
                        valueVector.set(i, value.toString().getBytes());
                    }
                }
                break;
            }
        case BINARY_TYPE:
            {
                VarBinaryVector valueVector = (VarBinaryVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        BinarySequence value = function.getBinary(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.setSafe(i, (value.getBytes()));
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        BinarySequence value = function.getBinary(record);
                        valueVector.set(i, value.getBytes());
                    }
                }
                break;
            }
        case UINT8_TYPE:
            break;
        case UINT16_TYPE:
            break;
        case UINT32_TYPE:
            break;
        case UINT64_TYPE:
            break;
        case TIME_MILLI_TYPE:
            {
                TimeMilliVector valueVector = (TimeMilliVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        int value = (int) function.getTime(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, (value));
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        int value = (int) function.getTime(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case DATE_TYPE:
            {
                DateMilliVector valueVector = (DateMilliVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getDate(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.set(i, value);
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getDate(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
        case DATETIME_MILLI_TYPE:
            {
                TimeStampMilliVector valueVector = (TimeStampMilliVector) outputVector;
                if (function.isNullableConstant()) {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getDatetime(record);
                        boolean isNull = function.isNull(record);
                        if (isNull) {
                            valueVector.setNull(i);
                        } else {
                            valueVector.setSafe(i, (value));
                        }
                    }
                } else {
                    for (int i = 0; i < rowCount; i++) {
                        record.setPosition(i);
                        long value = function.getDatetime(record);
                        valueVector.set(i, value);
                    }
                }
                break;
            }
    }
}
Also used : BinarySequence(io.ordinate.engine.function.BinarySequence) Record(io.ordinate.engine.record.Record)

Aggregations

Record (io.ordinate.engine.record.Record)5 BinarySequence (io.ordinate.engine.function.BinarySequence)3 Function (io.ordinate.engine.function.Function)2 RootContext (io.ordinate.engine.record.RootContext)2 Observable (io.reactivex.rxjava3.core.Observable)2 List (java.util.List)2 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)2 Schema (org.apache.arrow.vector.types.pojo.Schema)2 ImmutableList (com.google.common.collect.ImmutableList)1 MycatRxJavaUtl (io.mycat.MycatRxJavaUtl)1 PhysicalSortProperty (io.ordinate.engine.builder.PhysicalSortProperty)1 IntFunction (io.ordinate.engine.function.IntFunction)1 RecordImpl (io.ordinate.engine.record.RecordImpl)1 NonNull (io.reactivex.rxjava3.annotations.NonNull)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 IntUnaryOperator (java.util.function.IntUnaryOperator)1 org.apache.arrow.vector (org.apache.arrow.vector)1 Enumerable (org.apache.calcite.linq4j.Enumerable)1