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 return 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 UnsafeSorterIterator. spillReader . loadNext ( ) ; priorityQueue . add ( spillReader ) ; numRecords += spillReader . getNumRecords ( ) ; } }
Add an UnsafeSorterIterator to this merger