public void addSpillIfNotEmpty(UnsafeSorterIterator spillReader) throws IOException {
        if (spillReader.hasNext()) {
            // We only add the spillReader to the priorityQueue if it is not empty. We do this to
            // make sure the hasNext method of UnsafeSorterIterator returned by getSortedIterator
            // does not return wrong result because hasNext will returns true
            // at least priorityQueue.size() times. If we allow n spillReaders in the
            // priorityQueue, we will have n extra empty records in the result of the UnsafeSorterIterator.
            spillReader.loadNext();
            priorityQueue.add(spillReader);
            numRecords += spillReader.getNumRecords();
        }
    }
Add an UnsafeSorterIterator to this merger
indexr-query-opt/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeSorterSpillMerger.java