Search in sources :

Example 1 with TempFileReader

use of com.facebook.presto.hive.util.TempFileReader in project presto by prestodb.

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 DataSize(1, MEGABYTE), new DataSize(8, MEGABYTE), new DataSize(8, MEGABYTE), false, fileSystem.open(file), new FileFormatDataSourceStats());
            closer.register(dataSource);
            iterators.add(new TempFileReader(types, dataSource));
        }
        new MergingPageIterator(iterators, types, sortFields, sortOrders).forEachRemaining(consumer);
        if (!sortedWriteToTempPathEnabled) {
            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);
    }
}
Also used : Closer(com.google.common.io.Closer) Path(org.apache.hadoop.fs.Path) HdfsOrcDataSource(com.facebook.presto.hive.orc.HdfsOrcDataSource) OrcDataSource(com.facebook.presto.orc.OrcDataSource) MergingPageIterator(com.facebook.presto.hive.util.MergingPageIterator) OrcDataSourceId(com.facebook.presto.orc.OrcDataSourceId) ArrayList(java.util.ArrayList) HdfsOrcDataSource(com.facebook.presto.hive.orc.HdfsOrcDataSource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) DataSize(io.airlift.units.DataSize) MergingPageIterator(com.facebook.presto.hive.util.MergingPageIterator) Iterator(java.util.Iterator) TempFileReader(com.facebook.presto.hive.util.TempFileReader)

Aggregations

HdfsOrcDataSource (com.facebook.presto.hive.orc.HdfsOrcDataSource)1 MergingPageIterator (com.facebook.presto.hive.util.MergingPageIterator)1 TempFileReader (com.facebook.presto.hive.util.TempFileReader)1 OrcDataSource (com.facebook.presto.orc.OrcDataSource)1 OrcDataSourceId (com.facebook.presto.orc.OrcDataSourceId)1 Closer (com.google.common.io.Closer)1 DataSize (io.airlift.units.DataSize)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