public UnsafeSorterIterator getIterator ( int startIndex ) throws IOException { if ( spillWriters . isEmpty ( ) ) { assert ( inMemSorter != null ) ; UnsafeSorterIterator iter = inMemSorter . getSortedIterator ( ) ; moveOver ( iter , startIndex ) ; return iter ; } else { LinkedList < UnsafeSorterIterator > queue = new LinkedList <> ( ) ; int i = 0 ; for ( UnsafeSorterSpillWriter spillWriter : spillWriters ) { if ( i + spillWriter . recordsSpilled ( ) > startIndex ) { UnsafeSorterIterator iter = spillWriter . getReader ( serializerManager ) ; moveOver ( iter , startIndex - i ) ; queue . add ( iter ) ; } i += spillWriter . recordsSpilled ( ) ; } if ( inMemSorter != null ) { UnsafeSorterIterator iter = inMemSorter . getSortedIterator ( ) ; moveOver ( iter , startIndex - i ) ; queue . add ( iter ) ; } return new ChainedIterator ( queue ) ; } }
Returns an iterator starts from startIndex which will return the rows in the order as inserted .