@VisibleForTesting
  VectorizedRowBatch setupOverflowBatch(int firstOutputColumnIndex, String[] scratchColumnTypeNames,
      int[] outputProjectionColumnMap, TypeInfo[] outputTypeInfos) throws HiveException {

    int initialColumnCount = firstOutputColumnIndex;
    VectorizedRowBatch overflowBatch;

    int totalNumColumns = initialColumnCount + scratchColumnTypeNames.length;
    overflowBatch = new VectorizedRowBatch(totalNumColumns);

    // First, just allocate just the output columns we will be using.
    for (int i = 0; i < outputProjectionColumnMap.length; i++) {
      int outputColumn = outputProjectionColumnMap[i];
      String typeName = outputTypeInfos[i].getTypeName();
      allocateOverflowBatchColumnVector(overflowBatch, outputColumn, typeName,
          vOutContext.getDataTypePhysicalVariation(outputColumn));
    }

    // Now, add any scratch columns needed for children operators.
    int outputColumn = initialColumnCount;
    int s = 0;
    scratchColumnPositions = new int[scratchColumnTypeNames.length];
    for (String typeName : scratchColumnTypeNames) {
      allocateOverflowBatchColumnVector(overflowBatch, outputColumn, typeName,
          vOutContext.getDataTypePhysicalVariation(outputColumn));
      scratchColumnPositions[s] = outputColumn;
      outputColumn += 1;
      s += 1;
    }

    overflowBatch.projectedColumns = outputProjectionColumnMap;
    overflowBatch.projectionSize = outputProjectionColumnMap.length;

    overflowBatch.reset();

    return overflowBatch;
  }
Setup the vectorized row batch description of the output of the native vectorized PTF
operator.  Use the output projection we previously built from a mixture of input
columns and new scratch columns.
ql/src/java/org/apache/hadoop/hive/ql/exec/vector/ptf/VectorPTFOperator.java