Search in sources :

Example 6 with IntInnerType

use of io.ordinate.engine.schema.IntInnerType in project Mycat2 by MyCATApache.

the class FooRecordSink method copy.

@Override
public void copy(Record record, int rowId, VectorSchemaRoot input) {
    for (IntInnerType intPair : types) {
        int columnIndex = intPair.index;
        FieldVector vector = input.getVector(columnIndex);
        boolean aNull = record.isNull(columnIndex);
        if (aNull) {
            if (vector instanceof BaseFixedWidthVector) {
                ((BaseFixedWidthVector) vector).setNull(rowId);
            } else if (vector instanceof BaseVariableWidthVector) {
                ((BaseVariableWidthVector) vector).setNull(rowId);
            }
            continue;
        }
        InnerType innerType = intPair.type;
        switch(innerType) {
            case BOOLEAN_TYPE:
                BitVector bitVector = (BitVector) vector;
                bitVector.set(rowId, record.getInt(columnIndex));
                break;
            case CHAR_TYPE:
            case INT16_TYPE:
            case INT8_TYPE:
            case INT32_TYPE:
            case INT64_TYPE:
            case UINT8_TYPE:
            case UINT16_TYPE:
            case UINT32_TYPE:
            case UINT64_TYPE:
                BaseIntVector intVectors = (BaseIntVector) vector;
                intVectors.setUnsafeWithPossibleTruncate(rowId, record.getLong(columnIndex));
                break;
            case DOUBLE_TYPE:
            case FLOAT_TYPE:
                FloatingPointVector vectors = (FloatingPointVector) vector;
                vectors.setWithPossibleTruncate(rowId, record.getDouble(columnIndex));
                break;
            case SYMBOL_TYPE:
            case STRING_TYPE:
                VarCharVector valueVectors = (VarCharVector) vector;
                valueVectors.set(rowId, record.getBinary(columnIndex).getBytes());
                break;
            case BINARY_TYPE:
                {
                    VarBinaryVector varBinaryVector = (VarBinaryVector) vector;
                    varBinaryVector.set(rowId, record.getBinary(columnIndex).getBytes());
                    break;
                }
            case TIME_MILLI_TYPE:
                {
                    TimeMilliVector timeStampVector = (TimeMilliVector) vector;
                    timeStampVector.set(rowId, (int) record.getTime(columnIndex));
                    break;
                }
            case DATE_TYPE:
                {
                    DateMilliVector dateDayVector = (DateMilliVector) vector;
                    dateDayVector.set(rowId, record.getDate(columnIndex));
                    break;
                }
            case DATETIME_MILLI_TYPE:
                {
                    TimeStampVector timeStampVector = (TimeStampVector) vector;
                    timeStampVector.set(rowId, record.getTime(columnIndex));
                    break;
                }
            case OBJECT_TYPE:
                throw new UnsupportedOperationException();
            case NULL_TYPE:
                if (vector instanceof BaseFixedWidthVector) {
                    ((BaseFixedWidthVector) vector).setNull(rowId);
                } else if (vector instanceof BaseVariableWidthVector) {
                    ((BaseVariableWidthVector) vector).setNull(rowId);
                }
                continue;
        }
    }
}
Also used : InnerType(io.ordinate.engine.schema.InnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType)

Example 7 with IntInnerType

use of io.ordinate.engine.schema.IntInnerType in project Mycat2 by MyCATApache.

the class DistinctPlan method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    // DistinctContext distinctContext = new DistinctContext();
    IntInnerType[] intPairs = getIntTypes();
    Map map = MapFactory.createMap(intPairs);
    RecordSink recordSink = RecordSinkFactory.INSTANCE.buildRecordSink(intPairs);
    return input.execute(rootContext).flatMap(input -> {
        int rowCount = input.getRowCount();
        int columnCount = input.getFieldVectors().size();
        VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema(), rowCount);
        VectorBatchRecord record = new VectorBatchRecord(input);
        int outputRowId = 0;
        for (int rowId = 0; rowId < rowCount; rowId++) {
            record.setPosition(rowId);
            MapKey key = map.withKey();
            RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
            recordSink.copy(record, recordSinkSPI);
            if (key.create()) {
                recordSink.copy(record, outputRowId, output);
                outputRowId++;
            // output
            } else {
            // skip
            }
        }
        if (outputRowId == 0) {
            output.close();
            return Observable.empty();
        }
        output.setRowCount(outputRowId);
        return Observable.fromArray(output);
    }).doOnComplete(new Action() {

        @Override
        public void run() throws Throwable {
            map.close();
        }
    });
}
Also used : MapFactory(io.ordinate.engine.structure.MapFactory) Schema(org.apache.arrow.vector.types.pojo.Schema) Logger(org.slf4j.Logger) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) LoggerFactory(org.slf4j.LoggerFactory) RecordSinkFactory(io.ordinate.engine.record.RecordSinkFactory) RecordSetter(io.ordinate.engine.record.RecordSetter) RootContext(io.ordinate.engine.record.RootContext) MapKey(io.questdb.cairo.map.MapKey) Action(io.reactivex.rxjava3.functions.Action) Map(io.questdb.cairo.map.Map) List(java.util.List) IntInnerType(io.ordinate.engine.schema.IntInnerType) Observable(io.reactivex.rxjava3.core.Observable) VectorBatchRecord(io.ordinate.engine.record.VectorBatchRecord) Collections(java.util.Collections) RecordSink(io.ordinate.engine.record.RecordSink) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) RecordSetter(io.ordinate.engine.record.RecordSetter) Action(io.reactivex.rxjava3.functions.Action) MapKey(io.questdb.cairo.map.MapKey) RecordSink(io.ordinate.engine.record.RecordSink) Map(io.questdb.cairo.map.Map) VectorBatchRecord(io.ordinate.engine.record.VectorBatchRecord) IntInnerType(io.ordinate.engine.schema.IntInnerType)

Example 8 with IntInnerType

use of io.ordinate.engine.schema.IntInnerType in project Mycat2 by MyCATApache.

the class GroupByKeyPlan method execute.

@Override
public Observable<VectorSchemaRoot> execute(RootContext rootContext) {
    List<Field> fields = schema().getFields();
    InnerType[] innerTypes = schema().getFields().stream().map(i -> InnerType.from(i.getType())).toArray(n -> new InnerType[n]);
    Map map = MapFactory.createMap(innerTypes);
    RecordSink[] recordSinks = new RecordSink[groupByKeys.length];
    int groupIndex = 0;
    for (GroupKeys groupByKey : groupByKeys) {
        IntInnerType[] intPairs = new IntInnerType[groupByKey.getKeys().length];
        int[] keys = groupByKey.getKeys();
        int index = 0;
        for (int key : keys) {
            Field field = fields.get(key);
            intPairs[index] = IntInnerType.of(index, InnerType.from(field.getType()));
            index++;
        }
        recordSinks[groupIndex] = RecordSinkFactory.INSTANCE.buildRecordSink(intPairs);
        groupIndex++;
    }
    return inputPlan.execute(rootContext).flatMap(new Function<VectorSchemaRoot, ObservableSource<? extends VectorSchemaRoot>>() {

        @Override
        public ObservableSource<? extends VectorSchemaRoot> apply(VectorSchemaRoot input) throws Throwable {
            int rowCount = input.getRowCount();
            VectorBatchRecord record = new VectorBatchRecord(input);
            VectorSchemaRoot output = rootContext.getVectorSchemaRoot(schema, rowCount * recordSinks.length);
            int outputRowId = 0;
            for (int i = 0; i < recordSinks.length; i++) {
                RecordSink recordSink = recordSinks[i];
                for (int rowId = 0; rowId < rowCount; rowId++) {
                    record.setPosition(rowId);
                    MapKey key = map.withKey();
                    RecordSetter recordSinkSPI = RecordSinkFactory.INSTANCE.getRecordSinkSPI(key);
                    recordSink.copy(record, recordSinkSPI);
                    if (key.create()) {
                        recordSink.copy(record, outputRowId, output);
                        outputRowId++;
                    // output
                    } else {
                    // skip
                    }
                }
            }
            if (outputRowId == 0) {
                output.close();
                return Observable.empty();
            }
            output.setRowCount(outputRowId);
            inputPlan.eachFree(input);
            return Observable.fromArray(output);
        }
    }).doOnComplete(new Action() {

        @Override
        public void run() throws Throwable {
            map.close();
        }
    });
}
Also used : MapFactory(io.ordinate.engine.structure.MapFactory) ObservableSource(io.reactivex.rxjava3.core.ObservableSource) Schema(org.apache.arrow.vector.types.pojo.Schema) InnerType(io.ordinate.engine.schema.InnerType) Logger(org.slf4j.Logger) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) LoggerFactory(org.slf4j.LoggerFactory) RecordSinkFactory(io.ordinate.engine.record.RecordSinkFactory) RecordSetter(io.ordinate.engine.record.RecordSetter) Field(org.apache.arrow.vector.types.pojo.Field) RootContext(io.ordinate.engine.record.RootContext) MapKey(io.questdb.cairo.map.MapKey) Action(io.reactivex.rxjava3.functions.Action) Map(io.questdb.cairo.map.Map) GroupKeys(io.ordinate.engine.builder.GroupKeys) List(java.util.List) IntInnerType(io.ordinate.engine.schema.IntInnerType) Function(io.reactivex.rxjava3.functions.Function) Observable(io.reactivex.rxjava3.core.Observable) VectorBatchRecord(io.ordinate.engine.record.VectorBatchRecord) Collections(java.util.Collections) RecordSink(io.ordinate.engine.record.RecordSink) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) RecordSetter(io.ordinate.engine.record.RecordSetter) Action(io.reactivex.rxjava3.functions.Action) InnerType(io.ordinate.engine.schema.InnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType) Field(org.apache.arrow.vector.types.pojo.Field) Function(io.reactivex.rxjava3.functions.Function) MapKey(io.questdb.cairo.map.MapKey) GroupKeys(io.ordinate.engine.builder.GroupKeys) RecordSink(io.ordinate.engine.record.RecordSink) Map(io.questdb.cairo.map.Map) VectorBatchRecord(io.ordinate.engine.record.VectorBatchRecord)

Example 9 with IntInnerType

use of io.ordinate.engine.schema.IntInnerType in project Mycat2 by MyCATApache.

the class CodeGenRecordSinkFactoryImpl method buildRecordSink.

@Override
@SneakyThrows
public RecordSink buildRecordSink(IntInnerType[] types) {
    StringBuilder sb = new StringBuilder();
    for (IntInnerType type : types) {
        sb.append(type.type.getAlias());
    }
    sb.append(RecordSink.class.getSimpleName());
    String className = sb.toString();
    ClassDeclaration classDeclaration = Expressions.classDecl(java.lang.reflect.Modifier.PUBLIC, className, null, Arrays.asList(RecordSink.class), Arrays.asList(generateCopyRecordMethod(types), generateCopyRecordToVectorBatchMethod(types)));
    String s1 = Expressions.toString(classDeclaration);
    Class cookClass = CodeGenerator.cookClass(RecordSink.class.getClassLoader(), className, s1);
    return (RecordSink) cookClass.newInstance();
}
Also used : IntInnerType(io.ordinate.engine.schema.IntInnerType) SneakyThrows(lombok.SneakyThrows)

Example 10 with IntInnerType

use of io.ordinate.engine.schema.IntInnerType in project Mycat2 by MyCATApache.

the class CodeGenRecordSinkFactoryImpl method generateCopyRecordBody.

public static BlockStatement generateCopyRecordBody(IntInnerType[] types) {
    ArrayList<Statement> setterStatements = new ArrayList<>(types.length);
    for (int varIndex = 0; varIndex < types.length; varIndex++) {
        IntInnerType intPair = types[varIndex];
        int columnIndex = intPair.index;
        InnerType type = intPair.type;
        ConstantExpression index = Expressions.constant(columnIndex);
        MethodCallExpression isNullCondition = Expressions.call(from, "isNull", index);
        setterStatements.add(Expressions.ifThenElse(isNullCondition, Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "copyNullType", from, to, index)), Expressions.statement(Expressions.call(RecordSinkFactoryImpl.class, "copy" + type.name(), from, to, index))));
    }
    return Expressions.block(setterStatements);
}
Also used : ArrayList(java.util.ArrayList) InnerType(io.ordinate.engine.schema.InnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType)

Aggregations

IntInnerType (io.ordinate.engine.schema.IntInnerType)10 InnerType (io.ordinate.engine.schema.InnerType)7 Map (io.questdb.cairo.map.Map)3 MapKey (io.questdb.cairo.map.MapKey)3 NotNull (org.jetbrains.annotations.NotNull)3 GroupKeys (io.ordinate.engine.builder.GroupKeys)2 RecordSetter (io.ordinate.engine.record.RecordSetter)2 RecordSink (io.ordinate.engine.record.RecordSink)2 RecordSinkFactory (io.ordinate.engine.record.RecordSinkFactory)2 RootContext (io.ordinate.engine.record.RootContext)2 VectorBatchRecord (io.ordinate.engine.record.VectorBatchRecord)2 MapFactory (io.ordinate.engine.structure.MapFactory)2 Observable (io.reactivex.rxjava3.core.Observable)2 Action (io.reactivex.rxjava3.functions.Action)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)2 Field (org.apache.arrow.vector.types.pojo.Field)2 Schema (org.apache.arrow.vector.types.pojo.Schema)2