private static void findBestWorkingDeltas(ValidWriteIdList writeIdList, AcidDirectory directory) {
    Collections.sort(directory.getCurrentDirectories());
    //so now, 'current directories' should be sorted like delta_5_20 delta_5_10 delta_11_20 delta_51_60 for example
    //and we want to end up with the best set containing all relevant data: delta_5_20 delta_51_60,
    //subject to list of 'exceptions' in 'writeIdList' (not show in above example).
    List<ParsedDelta> deltas = new ArrayList<>();
    long current = directory.getBase() == null ? 0 : directory.getBase().getWriteId();
    int lastStmtId = -1;
    ParsedDelta prev = null;
    for(ParsedDelta next: directory.getCurrentDirectories()) {
      if (next.maxWriteId > current) {
        // are any of the new transactions ones that we care about?
        if (writeIdList.isWriteIdRangeValid(current+1, next.maxWriteId) !=
                ValidWriteIdList.RangeResponse.NONE) {
          deltas.add(next);
          current = next.maxWriteId;
          lastStmtId = next.statementId;
          prev = next;
        }
      }
      else if(next.maxWriteId == current && lastStmtId >= 0) {
        //make sure to get all deltas within a single transaction;  multi-statement txn
        //generate multiple delta files with the same txnId range
        //of course, if maxWriteId has already been minor compacted, all per statement deltas are obsolete
        deltas.add(next);
        prev = next;
      }
      else if (prev != null && next.maxWriteId == prev.maxWriteId
                  && next.minWriteId == prev.minWriteId
                  && next.statementId == prev.statementId) {
        // The 'next' parsedDelta may have everything equal to the 'prev' parsedDelta, except
        // the path. This may happen when we have split update and we have two types of delta
        // directories- 'delta_x_y' and 'delete_delta_x_y' for the SAME txn range.

        // Also note that any delete_deltas in between a given delta_x_y range would be made
        // obsolete. For example, a delta_30_50 would make delete_delta_40_40 obsolete.
        // This is valid because minor compaction always compacts the normal deltas and the delete
        // deltas for the same range. That is, if we had 3 directories, delta_30_30,
        // delete_delta_40_40 and delta_50_50, then running minor compaction would produce
        // delta_30_50 and delete_delta_30_50.

        deltas.add(next);
        prev = next;
      }
      else {
        directory.getObsolete().add(next.path);
      }
    }
    directory.getCurrentDirectories().clear();
    directory.getCurrentDirectories().addAll(deltas);
  }
GetAcidState implementation which uses the provided dirSnapshot.
Generates a new one if needed and the provided one is null.
@param fileSystem optional, it it is not provided, it will be derived from the candidateDirectory
@param candidateDirectory the partition directory to analyze
@param conf the configuration
@param writeIdList the list of write ids that we are reading
@param useFileIds It will be set to true, if the FileSystem supports listing with fileIds
@param ignoreEmptyFiles Ignore files with 0 length
@param dirSnapshots The listed directory snapshot, if null new will be generated
@return the state of the directory
@throws IOException on filesystem errors
ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java