use of org.apache.arrow.vector.holders.NullableIntervalDayHolder 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();
}
}
Aggregations