@Override
    public boolean hasNext() {
      if ((currentIterator == null) || (currentIterator.hasNext() == false)) {
        if (currentIndex == loadedSize) {
          return false;
        }

        try {
          if (readerArray[currentIndex] == null) {
            return false;
          }
          currentIterator = readerArray[currentIndex].getCurrentValues().iterator();
          currentIndex++;
          return currentIterator.hasNext();
        } catch (IOException e) {
          return false;
        }
      }

      return true;
    }
A KeyValuesReader implementation that returns a sorted stream of key-values
by doing a sorted merge of the key-value in LogicalInputs.
Tags are in the last byte of the key, so no special handling for tags is required.
Uses a priority queue to pick the KeyValuesReader of the input that is next in
sort order.
ql/src/java/org/apache/hadoop/hive/ql/exec/tez/tools/KeyValuesInputMerger.java