public static AcidKeyIndexValidationResult validate(Configuration conf, Path inputPath) throws IOException {
    AcidKeyIndexValidationResult result = new AcidKeyIndexValidationResult();
    FileSystem fs = inputPath.getFileSystem(conf);
    try (Reader reader = OrcFile.createReader(fs, inputPath);
        RecordReader rr = reader.rows()) {
      List<StripeInformation> stripes = reader.getStripes();
      RecordIdentifier[] keyIndex = OrcRecordUpdater.parseKeyIndex(reader);

      if (keyIndex == null) {
        result.isValid = false;
      }

      StructObjectInspector soi = (StructObjectInspector) reader.getObjectInspector();
      // struct<operation:int,originalTransaction:bigint,bucket:int,rowId:bigint,currentTransaction:bigint
      List<? extends StructField> structFields = soi.getAllStructFieldRefs();
      StructField transactionField = structFields.get(1);
      LongObjectInspector transactionOI = (LongObjectInspector) transactionField.getFieldObjectInspector();
      StructField bucketField = structFields.get(2);
      IntObjectInspector bucketOI = (IntObjectInspector) bucketField.getFieldObjectInspector();
      StructField rowIdField = structFields.get(3);
      LongObjectInspector rowIdOI = (LongObjectInspector) rowIdField.getFieldObjectInspector();

      long rowsProcessed = 0;
      for (int i = 0; i < stripes.size(); i++) {
        rowsProcessed += stripes.get(i).getNumberOfRows();
        rr.seekToRow(rowsProcessed - 1);
        OrcStruct row = (OrcStruct) rr.next(null);

        long lastTransaction = transactionOI.get(soi.getStructFieldData(row, transactionField));
        int lastBucket = bucketOI.get(soi.getStructFieldData(row, bucketField));
        long lastRowId = rowIdOI.get(soi.getStructFieldData(row, rowIdField));

        RecordIdentifier recordIdentifier = new RecordIdentifier(lastTransaction, lastBucket, lastRowId);
        result.recordIdentifiers.add(recordIdentifier);

        if (result.isValid && (stripes.size() != keyIndex.length || keyIndex[i] == null
            || recordIdentifier.compareTo(keyIndex[i]) != 0)) {
          result.isValid = false;
        }
      }
    }
    return result;
  }
Utility to check and fix the ACID key index of an ORC file if it has been written incorrectly
due to HIVE-18817.
The condition that will be checked in the ORC file will be if the number of stripes in the
acid key index matches the number of stripes in the ORC StripeInformation.
ql/src/java/org/apache/hadoop/hive/ql/io/orc/FixAcidKeyIndex.java