void innerTestVectorDeserializeRow(
      Random r, int iteration,
      SerializationType serializationType,
      boolean testDecimal64,
      boolean alternate1, boolean alternate2, boolean useExternalBuffer)
      throws HiveException, IOException, SerDeException {

    String title = "serializationType: " + serializationType + ", iteration " + iteration;

    String[] emptyScratchTypeNames = new String[0];

    VectorRandomRowSource source = new VectorRandomRowSource();

    // FUTURE: try NULLs and UNICODE.
    source.init(
        r, VectorRandomRowSource.SupportedTypes.ALL, 4,
        /* allowNulls */ false, /* isUnicodeOk */ false);

    VectorizedRowBatchCtx batchContext = new VectorizedRowBatchCtx();
    batchContext.init(source.rowStructObjectInspector(), emptyScratchTypeNames);
    VectorizedRowBatch batch = batchContext.createVectorizedRowBatch();

    // For Decimal64 tests, we manually change the VectorizedRowBatch to contain
    // a Decimal64ColumnVector.  While this may seem hacky, this is the way that it
    // is done within the VectorPTFOperator.
    if (testDecimal64) {
      for (int i = 0; i < batch.cols.length; ++i) {
        if (batch.cols[i] instanceof DecimalColumnVector) {
          DecimalColumnVector dcv = (DecimalColumnVector) batch.cols[i];
          if (dcv.precision <= 18) {
            String newType = String.format("decimal(%d,%d)", dcv.precision, dcv.scale);
            TypeInfo typeInfo = TypeInfoUtils.getTypeInfoFromTypeString(newType);
            batch.cols[i] = VectorizedBatchUtil.createColumnVector(typeInfo, DataTypePhysicalVariation.DECIMAL_64);
          }
        }
      }
    }

    // junk the destination for the 1st pass
    for (ColumnVector cv : batch.cols) {
      Arrays.fill(cv.isNull, true);
    }

    TypeInfo[] typeInfos = source.typeInfos();
    int fieldCount = source.typeNames().size();
    DeserializeRead deserializeRead;
    SerializeWrite serializeWrite;
    switch (serializationType) {
    case BINARY_SORTABLE:
      boolean useColumnSortOrderIsDesc = alternate1;
      if (!useColumnSortOrderIsDesc) {
        deserializeRead = BinarySortableDeserializeRead.ascendingNullsFirst(source.typeInfos(), useExternalBuffer);
        serializeWrite = new BinarySortableSerializeWrite(fieldCount);
      } else {
        boolean[] columnSortOrderIsDesc = new boolean[fieldCount];
        for (int i = 0; i < fieldCount; i++) {
          columnSortOrderIsDesc[i] = r.nextBoolean();
        }

        byte[] columnNullMarker = new byte[fieldCount];
        byte[] columnNotNullMarker = new byte[fieldCount];
        for (int i = 0; i < fieldCount; i++) {
          if (columnSortOrderIsDesc[i]) {
            // Descending
            // Null last (default for descending order)
            columnNullMarker[i] = BinarySortableSerDe.ZERO;
            columnNotNullMarker[i] = BinarySortableSerDe.ONE;
          } else {
            // Ascending
            // Null first (default for ascending order)
            columnNullMarker[i] = BinarySortableSerDe.ZERO;
            columnNotNullMarker[i] = BinarySortableSerDe.ONE;
          }
        }
        serializeWrite = new BinarySortableSerializeWrite(columnSortOrderIsDesc, columnNullMarker, columnNotNullMarker);
        deserializeRead = new BinarySortableDeserializeRead(source.typeInfos(), useExternalBuffer,
            columnSortOrderIsDesc, columnNullMarker, columnNotNullMarker);

      }
      boolean useBinarySortableCharsNeedingEscape = alternate2;
      if (useBinarySortableCharsNeedingEscape) {
        source.addBinarySortableAlphabets();
      }
      break;
    case LAZY_BINARY:
      deserializeRead = new LazyBinaryDeserializeRead(source.typeInfos(), useExternalBuffer);
      serializeWrite = new LazyBinarySerializeWrite(fieldCount);
      break;
    case LAZY_SIMPLE:
      {
        StructObjectInspector rowObjectInspector = source.rowStructObjectInspector();
        Configuration conf = new Configuration();
        Properties tbl = new Properties();
        tbl.setProperty(serdeConstants.FIELD_DELIM, "\t");
        tbl.setProperty(serdeConstants.LINE_DELIM, "\n");
        byte separator = (byte) '\t';
        boolean useLazySimpleEscapes = alternate1;
        if (useLazySimpleEscapes) {
          tbl.setProperty(serdeConstants.QUOTE_CHAR, "'");
          String escapeString = "\\";
          tbl.setProperty(serdeConstants.ESCAPE_CHAR, escapeString);
        }

        LazySerDeParameters lazySerDeParams =
            getSerDeParams(conf, tbl, rowObjectInspector, new byte[] { separator });

        if (useLazySimpleEscapes) {
          // LazySimple seems to throw away everything but \n and \r.
          boolean[] needsEscape = lazySerDeParams.getNeedsEscape();
          StringBuilder sb = new StringBuilder();
          if (needsEscape['\n']) {
            sb.append('\n');
          }
          if (needsEscape['\r']) {
            sb.append('\r');
          }
          // for (int i = 0; i < needsEscape.length; i++) {
          //  if (needsEscape[i]) {
          //    sb.append((char) i);
          //  }
          // }
          String needsEscapeStr = sb.toString();
          if (needsEscapeStr.length() > 0) {
            source.addEscapables(needsEscapeStr);
          }
        }
        deserializeRead =
            new LazySimpleDeserializeRead(source.typeInfos(), useExternalBuffer, lazySerDeParams);
        serializeWrite = new LazySimpleSerializeWrite(fieldCount, lazySerDeParams);
      }
      break;
    default:
      throw new Error("Unknown serialization type " + serializationType);
    }
    VectorDeserializeRow vectorDeserializeRow = new VectorDeserializeRow(deserializeRead);
    vectorDeserializeRow.init();

    // junk the destination for the 1st pass
    for (ColumnVector cv : batch.cols) {
      Arrays.fill(cv.isNull, true);
      cv.noNulls = false;
    }

    VectorExtractRow vectorExtractRow = new VectorExtractRow();
    vectorExtractRow.init(source.typeNames());

    Object[][] randomRows = source.randomRows(2000);
    int firstRandomRowIndex = 0;
    for (int i = 0; i < randomRows.length; i++) {
      Object[] row = randomRows[i];

      Output output = serializeRow(row, source, serializeWrite);
      vectorDeserializeRow.setBytes(output.getData(), 0, output.getLength());
      try {
        vectorDeserializeRow.deserialize(batch, batch.size);
      } catch (Exception e) {
        throw new HiveException(
            "\nDeserializeRead details: " +
                vectorDeserializeRow.getDetailedReadPositionString(),
            e);
      }
      batch.size++;
      if (batch.size == batch.DEFAULT_SIZE) {
        examineBatch(
            batch, vectorExtractRow, typeInfos, randomRows, firstRandomRowIndex,
            title);
        firstRandomRowIndex = i + 1;
        batch.reset();
      }
    }
    if (batch.size > 0) {
      examineBatch(
          batch, vectorExtractRow, typeInfos, randomRows, firstRandomRowIndex,
          title);
    }
  }
Unit test for the vectorized serialize and deserialize row.
ql/src/test/org/apache/hadoop/hive/ql/exec/vector/TestVectorSerDeRow.java