Search in sources :

Example 21 with InnerType

use of io.ordinate.engine.schema.InnerType 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)

Example 22 with InnerType

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

the class RecordSinkFactoryImpl method buildEqualComparator.

@Override
public RecordComparator buildEqualComparator(InnerType[] types) {
    return new RecordComparator() {

        Record leftRecord;

        Record rightRecord;

        @Override
        public int compare(Record record) {
            return compare(leftRecord, record);
        }

        @Override
        public int compare() {
            return compare(leftRecord, rightRecord);
        }

        @Override
        public void setLeft(Record record) {
            this.leftRecord = record;
        }

        @Override
        public void setRight(Record record) {
            this.rightRecord = record;
        }

        public int compare(Record left, Record right) {
            int length = types.length;
            int res = 0;
            for (int columnIndex = 0; columnIndex < length; columnIndex++) {
                InnerType type = types[columnIndex];
                switch(type) {
                    case BOOLEAN_TYPE:
                        {
                            res = Boolean.compare(left.getBooleanType(columnIndex), right.getBooleanType(columnIndex));
                            break;
                        }
                    case INT8_TYPE:
                        {
                            res = Integer.compare(left.getInt(columnIndex), right.getInt(columnIndex));
                            break;
                        }
                    case INT16_TYPE:
                        {
                            res = Short.compare(left.getShort(columnIndex), right.getShort(columnIndex));
                            break;
                        }
                    case CHAR_TYPE:
                        {
                            res = Character.compare(left.getCharType(columnIndex), right.getChar(columnIndex));
                            break;
                        }
                    case INT32_TYPE:
                        {
                            res = Integer.compare(left.getInt32Type(columnIndex), right.getInt32Type(columnIndex));
                            break;
                        }
                    case INT64_TYPE:
                        {
                            res = Long.compare(left.getInt64Type(columnIndex), right.getInt64Type(columnIndex));
                            break;
                        }
                    case FLOAT_TYPE:
                        {
                            res = Float.compare(left.getFloatType(columnIndex), right.getFloatType(columnIndex));
                            break;
                        }
                    case DOUBLE_TYPE:
                        {
                            res = Double.compare(left.getDoubleType(columnIndex), right.getDoubleType(columnIndex));
                            break;
                        }
                    case STRING_TYPE:
                        {
                            res = left.getString(columnIndex).toString().compareTo(right.getString(columnIndex).toString());
                            break;
                        }
                    case BINARY_TYPE:
                        {
                            BinarySequence leftBinary = left.getBinary(columnIndex);
                            BinarySequence rightBinary = right.getBinary(columnIndex);
                            res = leftBinary.compareTo(rightBinary);
                            break;
                        }
                    case UINT8_TYPE:
                        {
                            int l = Byte.toUnsignedInt(left.getUInt8Type(columnIndex));
                            int r = Byte.toUnsignedInt(right.getUInt8Type(columnIndex));
                            res = Integer.compare(l, r);
                            break;
                        }
                    case UINT16_TYPE:
                        {
                            int l = Short.toUnsignedInt(left.getUInt16(columnIndex));
                            int r = Short.toUnsignedInt(right.getUInt16(columnIndex));
                            res = Integer.compare(l, r);
                            break;
                        }
                    case UINT32_TYPE:
                        {
                            long l = Integer.toUnsignedLong(left.getUInt32(columnIndex));
                            long r = Integer.toUnsignedLong(right.getUInt32(columnIndex));
                            res = Long.compare(l, r);
                            break;
                        }
                    case UINT64_TYPE:
                        {
                            res = UnsignedLong.fromLongBits(left.getUInt64(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getUInt64(columnIndex)));
                            break;
                        }
                    case TIME_MILLI_TYPE:
                        {
                            res = UnsignedLong.fromLongBits(left.getTime(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getTime(columnIndex)));
                            break;
                        }
                    case DATE_TYPE:
                        {
                            res = UnsignedLong.fromLongBits(left.getDate(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getDate(columnIndex)));
                            break;
                        }
                    case DATETIME_MILLI_TYPE:
                        {
                            res = UnsignedLong.fromLongBits(left.getDatetime(columnIndex)).compareTo(UnsignedLong.fromLongBits(right.getDatetime(columnIndex)));
                            break;
                        }
                    case SYMBOL_TYPE:
                        {
                            res = left.getSymbol(columnIndex).toString().compareTo((right.getSymbol(columnIndex)).toString());
                            break;
                        }
                    case OBJECT_TYPE:
                    case NULL_TYPE:
                    default:
                        throw new IllegalArgumentException();
                }
                if (res == 0) {
                } else {
                    return res;
                }
            }
            return 0;
        }
    };
}
Also used : BinarySequence(io.ordinate.engine.function.BinarySequence) InnerType(io.ordinate.engine.schema.InnerType) IntInnerType(io.ordinate.engine.schema.IntInnerType)

Example 23 with InnerType

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

the class ResultWriterUtil method resultSetColumnToVectorRowSchema.

public static Schema resultSetColumnToVectorRowSchema(MycatRowMetaData mycatRowMetaData) {
    int columnCount = mycatRowMetaData.getColumnCount();
    ImmutableList.Builder<Field> builder = ImmutableList.builder();
    for (int i = 0; i < columnCount; i++) {
        String columnName = mycatRowMetaData.getColumnName(i);
        int columnType = mycatRowMetaData.getColumnType(i);
        boolean signed = mycatRowMetaData.isSigned(i);
        boolean nullable = mycatRowMetaData.isNullable(i);
        InnerType innerType = InnerType.fromJdbc(columnType);
        if (!signed) {
            innerType = innerType.toUnsigned();
        }
        Field field = FieldBuilder.of(columnName, innerType.getArrowType(), nullable).toArrow();
        builder.add(field);
    }
    return new org.apache.arrow.vector.types.pojo.Schema(builder.build());
}
Also used : Field(org.apache.arrow.vector.types.pojo.Field) ImmutableList(com.google.common.collect.ImmutableList) Schema(org.apache.arrow.vector.types.pojo.Schema) InnerType(io.ordinate.engine.schema.InnerType)

Aggregations

InnerType (io.ordinate.engine.schema.InnerType)23 IntInnerType (io.ordinate.engine.schema.IntInnerType)10 Schema (org.apache.arrow.vector.types.pojo.Schema)6 Field (org.apache.arrow.vector.types.pojo.Field)5 Function (io.ordinate.engine.function.Function)4 ImmutableList (com.google.common.collect.ImmutableList)3 AccumulatorFunction (io.ordinate.engine.function.aggregate.AccumulatorFunction)3 Map (io.questdb.cairo.map.Map)3 MapKey (io.questdb.cairo.map.MapKey)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)3 GroupKeys (io.ordinate.engine.builder.GroupKeys)2 VariableParameterFunction (io.ordinate.engine.function.bind.VariableParameterFunction)2 MapFactory (io.ordinate.engine.structure.MapFactory)2 SimpleMapValue (io.questdb.griffin.engine.groupby.SimpleMapValue)2 Observable (io.reactivex.rxjava3.core.Observable)2 Function (io.reactivex.rxjava3.functions.Function)2 Collections (java.util.Collections)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2