presto-hive/src/main/java/io/prestosql/plugin/hive/SortingFileWriter.java/SortingFileWriter/mergeFiles
class SortingFileWriter:    private void mergeFiles(Iterable<TempFile> files, Consumer<Page> consumer)
    {
        try (Closer closer = Closer.create()) {
            Collection<Iterator<Page>> iterators = new ArrayList<>();

            for (TempFile tempFile : files) {
                Path file = tempFile.getPath();
                OrcDataSource dataSource = new HdfsOrcDataSource(
                        new OrcDataSourceId(file.toString()),
                        fileSystem.getFileStatus(file).getLen(),
                        new OrcReaderOptions(),
                        fileSystem.open(file),
                        new FileFormatDataSourceStats());
                closer.register(dataSource);
                iterators.add(new TempFileReader(types, dataSource));
            }

            new MergingPageIterator(iterators, types, sortFields, sortOrders)
                    .forEachRemaining(consumer);

            for (TempFile tempFile : files) {
                Path file = tempFile.getPath();
                fileSystem.delete(file, false);
                if (fileSystem.exists(file)) {
                    throw new IOException("Failed to delete temporary file: " + file);
                }
            }
        }
        catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }