public UnsafeSorterIterator getIterator() throws IOException {
        if (spillWriters.isEmpty()) {
            assert (inMemSorter != null);
            return inMemSorter.getSortedIterator();
        } else {
            LinkedList<UnsafeSorterIterator> queue = new LinkedList<>();
            for (UnsafeSorterSpillWriter spillWriter : spillWriters) {
                queue.add(spillWriter.getReader());
            }
            if (inMemSorter != null) {
                queue.add(inMemSorter.getSortedIterator());
            }
            return new ChainedIterator(queue);
        }
    }
Returns a iterator, which will return the rows in the order as inserted.

It is the caller's responsibility to call `cleanupResources()`
after consuming this iterator.

TODO: support forced spilling
indexr-query-opt/src/main/java/org/apache/spark/util/collection/unsafe/sort/UnsafeExternalSorter.java