public static void copyNonSelectedColumnVector(
      VectorizedRowBatch sourceBatch, int sourceColumnNum,
      VectorizedRowBatch targetBatch, int targetColumnNum,
      int size, int startIndex) {

    ColumnVector sourceColVector = sourceBatch.cols[sourceColumnNum];
    ColumnVector targetColVector = targetBatch.cols[targetColumnNum];
    if (sourceColVector.noNulls && targetColVector.noNulls) {
      // No isNull copying necessary.
    } else if (sourceColVector.noNulls) {

      // Clear out isNull array.
      targetColVector.reset();
    } else {
      System.arraycopy(sourceColVector.isNull, 0, targetColVector.isNull, 0, size);
      targetColVector.noNulls = false;
    }
    if (sourceColVector.isRepeating) {
      size = 1;
      startIndex = 0; // we must copy the first item in case of isRepeating
      targetColVector.isRepeating = true;
    } else {
      targetColVector.isRepeating = false;
    }

    // Primitive column types ignore nulls and just copy all values.
    switch (sourceColVector.type) {
    case LONG:
      {
        long[] sourceVector = ((LongColumnVector) sourceColVector).vector;
        long[] targetVector = ((LongColumnVector) targetColVector).vector;
        System.arraycopy(sourceVector, startIndex, targetVector, 0, size);
      }
      break;
    case DOUBLE:
      {
        double[] sourceVector = ((DoubleColumnVector) sourceColVector).vector;
        double[] targetVector = ((DoubleColumnVector) targetColVector).vector;
        System.arraycopy(sourceVector, startIndex, targetVector, 0, size);
      }
      break;
    case BYTES:
      {
        BytesColumnVector sourceBytesColVector = ((BytesColumnVector) sourceColVector);
        byte[][] sourceVector = sourceBytesColVector.vector;
        int[] sourceStart = sourceBytesColVector.start;
        int[] sourceLength = sourceBytesColVector.length;
  
        BytesColumnVector targetBytesColVector = ((BytesColumnVector) targetColVector);
  
        if (sourceColVector.noNulls) {
          for (int i = startIndex; i < size; i++) {
            targetBytesColVector.setVal(i, sourceVector[i], sourceStart[i], sourceLength[i]);
          }
        } else {
          boolean[] sourceIsNull = sourceColVector.isNull;
  
          // Target isNull was copied at beginning of method.
          for (int i = startIndex; i < size; i++) {
            if (!sourceIsNull[i]) {
              targetBytesColVector.setVal(i, sourceVector[i], sourceStart[i], sourceLength[i]);
            } else {
              targetBytesColVector.setRef(i, EMPTY_BYTES, 0, 0);
            }
          }
        }
      }
      break;
    case DECIMAL:
      {
        DecimalColumnVector sourceDecimalColVector = ((DecimalColumnVector) sourceColVector);
        HiveDecimalWritable[] sourceVector = sourceDecimalColVector.vector;

        DecimalColumnVector targetDecimalColVector = ((DecimalColumnVector) targetColVector);

        if (sourceColVector.noNulls) {
          for (int i = startIndex; i < size; i++) {
            targetDecimalColVector.set(i, sourceVector[i]);
          }
        } else {
          boolean[] sourceIsNull = sourceColVector.isNull;

          // Target isNull was copied at beginning of method.
          for (int i = startIndex; i < size; i++) {
            if (!sourceIsNull[i]) {
              targetDecimalColVector.set(i, sourceVector[i]);
            } else {
              targetDecimalColVector.vector[i].setFromLong(0);
            }
          }
        }
      }
      break;
    case TIMESTAMP:
      {
        TimestampColumnVector sourceTimestampColVector = ((TimestampColumnVector) sourceColVector);
        long[] sourceTime = sourceTimestampColVector.time;
        int[] sourceNanos = sourceTimestampColVector.nanos;

        TimestampColumnVector targetTimestampColVector = ((TimestampColumnVector) targetColVector);
        long[] targetTime = targetTimestampColVector.time;
        int[] targetNanos = targetTimestampColVector.nanos;

        if (sourceColVector.noNulls) {
          for (int i = startIndex; i < size; i++) {
            targetTime[i] = sourceTime[i];
            targetNanos[i] = sourceNanos[i];
          }
        } else {
          boolean[] sourceIsNull = sourceColVector.isNull;
  
          // Target isNull was copied at beginning of method.
          for (int i = startIndex; i < size; i++) {
            if (!sourceIsNull[i]) {
              targetTime[i] = sourceTime[i];
              targetNanos[i] = sourceNanos[i];
            } else {
              targetTime[i] = 0;
              targetNanos[i] = 0;
            }
          }
        }
      }
      break;
    case INTERVAL_DAY_TIME:
      {
        IntervalDayTimeColumnVector sourceIntervalDayTimeColVector = ((IntervalDayTimeColumnVector) sourceColVector);

        IntervalDayTimeColumnVector targetIntervalDayTimeColVector = ((IntervalDayTimeColumnVector) targetColVector);

        if (sourceColVector.noNulls) {
          for (int i = startIndex; i < size; i++) {
            targetIntervalDayTimeColVector.set(
                i, targetIntervalDayTimeColVector.asScratchIntervalDayTime(i));
          }
        } else {
          boolean[] sourceIsNull = sourceColVector.isNull;

          // Target isNull was copied at beginning of method.
          for (int i = startIndex; i < size; i++) {
            if (!sourceIsNull[i]) {
              targetIntervalDayTimeColVector.set(
                  i, targetIntervalDayTimeColVector.asScratchIntervalDayTime(i));
            } else {
              targetIntervalDayTimeColVector.set(
                  i, emptyIntervalDayTime);
            }
          }
        }
      }
      break;
    case STRUCT:
    case LIST:
    case MAP:
    case UNION:
      throw new RuntimeException("No complex type support: " + sourceColVector.type);
    case VOID:
      break;
    default:
      throw new RuntimeException("Unexpected column vector type " + sourceColVector.type);
    }
 
  }
Iterates thru all the columns in a given row and populates the batch
from a given offset

@param row Deserialized row object
@param oi Object insepector for that row
@param rowIndex index to which the row should be added to batch
@param batch Vectorized batch to which the row is added at rowIndex
@param context context object for this vectorized batch
@param buffer
@throws HiveException
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/VectorizedBatchUtil.java