Search in sources :

Example 1 with HiveCompressionCodec

use of com.facebook.presto.hive.HiveCompressionCodec in project presto by prestodb.

the class PageFileWriterFactory method createFileWriter.

@Override
public Optional<HiveFileWriter> createFileWriter(Path path, List<String> inputColumnNames, StorageFormat storageFormat, Properties schema, JobConf configuration, ConnectorSession session, Optional<EncryptionInformation> encryptionInformation) {
    if (!storageFormat.getOutputFormat().equals(PAGEFILE.getOutputFormat())) {
        return Optional.empty();
    }
    HiveCompressionCodec compression = HiveCompressionCodec.valueOf(configuration.get(PAGE_FILE_COMPRESSION));
    if (!compression.isSupportedStorageFormat(PAGEFILE)) {
        throw new PrestoException(GENERIC_USER_ERROR, format("%s compression is not supported for %s", compression.name(), PAGEFILE.getOutputFormat()));
    }
    PagesSerde pagesSerde = createPagesSerdeForPageFile(blockEncodingSerde, Optional.of(compression));
    try {
        FileSystem fileSystem = hdfsEnvironment.getFileSystem(session.getUser(), path, configuration);
        DataSink dataSink = dataSinkFactory.createDataSink(session, fileSystem, path);
        Callable<Void> rollbackAction = () -> {
            fileSystem.delete(path, false);
            return null;
        };
        return Optional.of(new PageFileWriter(dataSink, pagesSerde, compression, getPageFileStripeMaxSize(session), rollbackAction));
    } catch (IOException e) {
        throw new PrestoException(HIVE_WRITER_OPEN_ERROR, "Error creating pagefile", e);
    }
}
Also used : DataSink(com.facebook.presto.common.io.DataSink) PagesSerde(com.facebook.presto.spi.page.PagesSerde) HiveCompressionCodec(com.facebook.presto.hive.HiveCompressionCodec) FileSystem(org.apache.hadoop.fs.FileSystem) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException)

Aggregations

DataSink (com.facebook.presto.common.io.DataSink)1 HiveCompressionCodec (com.facebook.presto.hive.HiveCompressionCodec)1 PrestoException (com.facebook.presto.spi.PrestoException)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 IOException (java.io.IOException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1