Search in sources :

Example 1 with TempFileReader

use of io.trino.plugin.hive.util.TempFileReader in project trino by trinodb.

the class SortingFileWriter method mergeFiles.

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, typeOperators).forEachRemaining(consumer);
        for (TempFile tempFile : files) {
            Path file = tempFile.getPath();
            if (!fileSystem.delete(file, false)) {
                throw new IOException("Failed to delete temporary file: " + file);
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Closer(com.google.common.io.Closer) Path(org.apache.hadoop.fs.Path) OrcDataSource(io.trino.orc.OrcDataSource) HdfsOrcDataSource(io.trino.plugin.hive.orc.HdfsOrcDataSource) MergingPageIterator(io.trino.plugin.hive.util.MergingPageIterator) OrcDataSourceId(io.trino.orc.OrcDataSourceId) ArrayList(java.util.ArrayList) HdfsOrcDataSource(io.trino.plugin.hive.orc.HdfsOrcDataSource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) OrcReaderOptions(io.trino.orc.OrcReaderOptions) MergingPageIterator(io.trino.plugin.hive.util.MergingPageIterator) Iterator(java.util.Iterator) TempFileReader(io.trino.plugin.hive.util.TempFileReader)

Aggregations

Closer (com.google.common.io.Closer)1 OrcDataSource (io.trino.orc.OrcDataSource)1 OrcDataSourceId (io.trino.orc.OrcDataSourceId)1 OrcReaderOptions (io.trino.orc.OrcReaderOptions)1 HdfsOrcDataSource (io.trino.plugin.hive.orc.HdfsOrcDataSource)1 MergingPageIterator (io.trino.plugin.hive.util.MergingPageIterator)1 TempFileReader (io.trino.plugin.hive.util.TempFileReader)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Path (org.apache.hadoop.fs.Path)1