Search in sources :

Example 1 with IntervalYearVector

use of org.apache.arrow.vector.IntervalYearVector in project hive by apache.

the class Deserializer method readPrimitive.

private void readPrimitive(FieldVector arrowVector, ColumnVector hiveVector) {
    final Types.MinorType minorType = arrowVector.getMinorType();
    final int size = arrowVector.getValueCount();
    switch(minorType) {
        case BIT:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((BitVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case TINYINT:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((TinyIntVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case SMALLINT:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((SmallIntVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case INT:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((IntVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case BIGINT:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((BigIntVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case FLOAT4:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((DoubleColumnVector) hiveVector).vector[i] = ((Float4Vector) arrowVector).get(i);
                    }
                }
            }
            break;
        case FLOAT8:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((DoubleColumnVector) hiveVector).vector[i] = ((Float8Vector) arrowVector).get(i);
                    }
                }
            }
            break;
        case VARCHAR:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((BytesColumnVector) hiveVector).setVal(i, ((VarCharVector) arrowVector).get(i));
                    }
                }
            }
            break;
        case DATEDAY:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((DateDayVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case TIMESTAMPMILLI:
        case TIMESTAMPMILLITZ:
        case TIMESTAMPMICRO:
        case TIMESTAMPMICROTZ:
        case TIMESTAMPNANO:
        case TIMESTAMPNANOTZ:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        // Time = second + sub-second
                        final long time = ((TimeStampVector) arrowVector).get(i);
                        long second;
                        int subSecondInNanos;
                        switch(minorType) {
                            case TIMESTAMPMILLI:
                            case TIMESTAMPMILLITZ:
                                {
                                    subSecondInNanos = (int) ((time % MILLIS_PER_SECOND) * NS_PER_MILLIS);
                                    second = time / MILLIS_PER_SECOND;
                                }
                                break;
                            case TIMESTAMPMICROTZ:
                            case TIMESTAMPMICRO:
                                {
                                    subSecondInNanos = (int) ((time % MICROS_PER_SECOND) * NS_PER_MICROS);
                                    second = time / MICROS_PER_SECOND;
                                }
                                break;
                            case TIMESTAMPNANOTZ:
                            case TIMESTAMPNANO:
                                {
                                    subSecondInNanos = (int) (time % NS_PER_SECOND);
                                    second = time / NS_PER_SECOND;
                                }
                                break;
                            default:
                                throw new IllegalArgumentException();
                        }
                        final TimestampColumnVector timestampColumnVector = (TimestampColumnVector) hiveVector;
                        // A nanosecond value should not be negative
                        if (subSecondInNanos < 0) {
                            // So add one second to the negative nanosecond value to make it positive
                            subSecondInNanos += NS_PER_SECOND;
                            // Subtract one second from the second value because we added one second
                            second -= 1;
                        }
                        timestampColumnVector.time[i] = second * MILLIS_PER_SECOND;
                        timestampColumnVector.nanos[i] = subSecondInNanos;
                    }
                }
            }
            break;
        case VARBINARY:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((BytesColumnVector) hiveVector).setVal(i, ((VarBinaryVector) arrowVector).get(i));
                    }
                }
            }
            break;
        case DECIMAL:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((DecimalColumnVector) hiveVector).set(i, HiveDecimal.create(((DecimalVector) arrowVector).getObject(i)));
                    }
                }
            }
            break;
        case INTERVALYEAR:
            {
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        ((LongColumnVector) hiveVector).vector[i] = ((IntervalYearVector) arrowVector).get(i);
                    }
                }
            }
            break;
        case INTERVALDAY:
            {
                final IntervalDayVector intervalDayVector = (IntervalDayVector) arrowVector;
                final NullableIntervalDayHolder intervalDayHolder = new NullableIntervalDayHolder();
                final HiveIntervalDayTime intervalDayTime = new HiveIntervalDayTime();
                for (int i = 0; i < size; i++) {
                    if (arrowVector.isNull(i)) {
                        VectorizedBatchUtil.setNullColIsNullValue(hiveVector, i);
                    } else {
                        hiveVector.isNull[i] = false;
                        intervalDayVector.get(i, intervalDayHolder);
                        final long seconds = intervalDayHolder.days * SECOND_PER_DAY + intervalDayHolder.milliseconds / MILLIS_PER_SECOND;
                        final int nanos = (intervalDayHolder.milliseconds % 1_000) * NS_PER_MILLIS;
                        intervalDayTime.set(seconds, nanos);
                        ((IntervalDayTimeColumnVector) hiveVector).set(i, intervalDayTime);
                    }
                }
            }
            break;
        default:
            throw new IllegalArgumentException();
    }
}
Also used : Types(org.apache.arrow.vector.types.Types) BitVector(org.apache.arrow.vector.BitVector) TimestampColumnVector(org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector) NullableIntervalDayHolder(org.apache.arrow.vector.holders.NullableIntervalDayHolder) IntervalDayVector(org.apache.arrow.vector.IntervalDayVector) SmallIntVector(org.apache.arrow.vector.SmallIntVector) BigIntVector(org.apache.arrow.vector.BigIntVector) TinyIntVector(org.apache.arrow.vector.TinyIntVector) IntVector(org.apache.arrow.vector.IntVector) SmallIntVector(org.apache.arrow.vector.SmallIntVector) Float4Vector(org.apache.arrow.vector.Float4Vector) Float8Vector(org.apache.arrow.vector.Float8Vector) VarCharVector(org.apache.arrow.vector.VarCharVector) VarBinaryVector(org.apache.arrow.vector.VarBinaryVector) BigIntVector(org.apache.arrow.vector.BigIntVector) IntervalYearVector(org.apache.arrow.vector.IntervalYearVector) DateDayVector(org.apache.arrow.vector.DateDayVector) TinyIntVector(org.apache.arrow.vector.TinyIntVector) HiveIntervalDayTime(org.apache.hadoop.hive.common.type.HiveIntervalDayTime)

Aggregations

BigIntVector (org.apache.arrow.vector.BigIntVector)1 BitVector (org.apache.arrow.vector.BitVector)1 DateDayVector (org.apache.arrow.vector.DateDayVector)1 Float4Vector (org.apache.arrow.vector.Float4Vector)1 Float8Vector (org.apache.arrow.vector.Float8Vector)1 IntVector (org.apache.arrow.vector.IntVector)1 IntervalDayVector (org.apache.arrow.vector.IntervalDayVector)1 IntervalYearVector (org.apache.arrow.vector.IntervalYearVector)1 SmallIntVector (org.apache.arrow.vector.SmallIntVector)1 TinyIntVector (org.apache.arrow.vector.TinyIntVector)1 VarBinaryVector (org.apache.arrow.vector.VarBinaryVector)1 VarCharVector (org.apache.arrow.vector.VarCharVector)1 NullableIntervalDayHolder (org.apache.arrow.vector.holders.NullableIntervalDayHolder)1 Types (org.apache.arrow.vector.types.Types)1 HiveIntervalDayTime (org.apache.hadoop.hive.common.type.HiveIntervalDayTime)1 TimestampColumnVector (org.apache.hadoop.hive.ql.exec.vector.TimestampColumnVector)1