Search in sources :

Example 6 with PagesSerde

use of com.facebook.presto.spi.page.PagesSerde in project presto by prestodb.

the class PageFileWriterFactory method createPagesSerdeForPageFile.

public static PagesSerde createPagesSerdeForPageFile(BlockEncodingSerde blockEncodingSerde, Optional<HiveCompressionCodec> compressionCodec) {
    if (!compressionCodec.isPresent()) {
        return new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
    }
    PageCompressor pageCompressor = null;
    PageDecompressor pageDecompressor = null;
    switch(compressionCodec.get()) {
        case NONE:
            break;
        case SNAPPY:
            pageCompressor = new AirliftCompressorAdapter(new SnappyCompressor());
            pageDecompressor = new AirliftDecompressorAdapter(new SnappyDecompressor());
            break;
        case LZ4:
            pageCompressor = new AirliftCompressorAdapter(new Lz4Compressor());
            pageDecompressor = new AirliftDecompressorAdapter(new Lz4Decompressor());
            break;
        case GZIP:
            pageCompressor = new AirliftCompressorAdapter(new DeflateCompressor(OptionalInt.empty()));
            pageDecompressor = new AirliftDecompressorAdapter(new InflateDecompressor());
            break;
        case ZSTD:
            pageCompressor = new AirliftCompressorAdapter(new ZstdJniCompressor(OptionalInt.empty()));
            pageDecompressor = new AirliftDecompressorAdapter(new ZstdJniDecompressor());
            break;
        default:
            throw new PrestoException(GENERIC_INTERNAL_ERROR, format("%s compression is not supported for %s", compressionCodec.get().name(), PAGEFILE.getOutputFormat()));
    }
    return new PagesSerde(blockEncodingSerde, Optional.ofNullable(pageCompressor), Optional.ofNullable(pageDecompressor), Optional.empty());
}
Also used : PageCompressor(com.facebook.presto.spi.page.PageCompressor) Lz4Compressor(io.airlift.compress.lz4.Lz4Compressor) DeflateCompressor(com.facebook.presto.orc.zlib.DeflateCompressor) PrestoException(com.facebook.presto.spi.PrestoException) SnappyDecompressor(io.airlift.compress.snappy.SnappyDecompressor) PagesSerde(com.facebook.presto.spi.page.PagesSerde) SnappyCompressor(io.airlift.compress.snappy.SnappyCompressor) Lz4Decompressor(io.airlift.compress.lz4.Lz4Decompressor) InflateDecompressor(com.facebook.presto.orc.zlib.InflateDecompressor) ZstdJniDecompressor(com.facebook.presto.orc.zstd.ZstdJniDecompressor) ZstdJniCompressor(com.facebook.presto.orc.zstd.ZstdJniCompressor) PageDecompressor(com.facebook.presto.spi.page.PageDecompressor)

Example 7 with PagesSerde

use of com.facebook.presto.spi.page.PagesSerde in project presto by prestodb.

the class GrpcUtils method toGrpcSerializedPage.

public static GrpcSerializedPage toGrpcSerializedPage(BlockEncodingSerde blockEncodingSerde, Page prestoPage) {
    PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
    SerializedPage serializedPage = pagesSerde.serialize(prestoPage);
    return GrpcSerializedPage.newBuilder().setSliceBytes(ByteString.copyFrom(serializedPage.getSlice().getBytes())).setPositionCount(serializedPage.getPositionCount()).setUncompressedSizeInBytes(serializedPage.getUncompressedSizeInBytes()).setPageCodecMarkers(ByteString.copyFrom(new byte[] { serializedPage.getPageCodecMarkers() })).setChecksum(serializedPage.getChecksum()).build();
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) GrpcSerializedPage(com.facebook.presto.grpc.udf.GrpcSerializedPage) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 8 with PagesSerde

use of com.facebook.presto.spi.page.PagesSerde 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)

Example 9 with PagesSerde

use of com.facebook.presto.spi.page.PagesSerde in project presto by prestodb.

the class TestSpillCipherPagesSerde method test.

@Test
public void test() {
    SpillCipher cipher = new AesSpillCipher();
    PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerdeForSpill(Optional.of(cipher));
    List<Type> types = ImmutableList.of(VARCHAR);
    Page emptyPage = new Page(VARCHAR.createBlockBuilder(null, 0).build());
    assertPageEquals(types, serde.deserialize(serde.serialize(emptyPage)), emptyPage);
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 2);
    VARCHAR.writeString(blockBuilder, "hello");
    VARCHAR.writeString(blockBuilder, "world");
    Page helloWorldPage = new Page(blockBuilder.build());
    SerializedPage serialized = serde.serialize(helloWorldPage);
    assertPageEquals(types, serde.deserialize(serialized), helloWorldPage);
    assertTrue(ENCRYPTED.isSet(serialized.getPageCodecMarkers()), "page should be encrypted");
    cipher.destroy();
    assertFailure(() -> serde.serialize(helloWorldPage), "Spill cipher already destroyed");
    assertFailure(() -> serde.deserialize(serialized), "Spill cipher already destroyed");
}
Also used : Type(com.facebook.presto.common.type.Type) PagesSerde(com.facebook.presto.spi.page.PagesSerde) TestingPagesSerdeFactory(com.facebook.presto.execution.buffer.TestingPagesSerdeFactory) Page(com.facebook.presto.common.Page) SerializedPage(com.facebook.presto.spi.page.SerializedPage) SerializedPage(com.facebook.presto.spi.page.SerializedPage) SpillCipher(com.facebook.presto.spi.spiller.SpillCipher) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 10 with PagesSerde

use of com.facebook.presto.spi.page.PagesSerde in project presto by prestodb.

the class TestPagesSerde method testRoundTrip.

@Test
public void testRoundTrip() {
    PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde();
    BlockBuilder expectedBlockBuilder = VARCHAR.createBlockBuilder(null, 5);
    VARCHAR.writeString(expectedBlockBuilder, "alice");
    VARCHAR.writeString(expectedBlockBuilder, "bob");
    VARCHAR.writeString(expectedBlockBuilder, "charlie");
    VARCHAR.writeString(expectedBlockBuilder, "dave");
    Block expectedBlock = expectedBlockBuilder.build();
    Page expectedPage = new Page(expectedBlock, expectedBlock, expectedBlock);
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    writePages(serde, sliceOutput, expectedPage, expectedPage, expectedPage);
    List<Type> types = ImmutableList.of(VARCHAR, VARCHAR, VARCHAR);
    Iterator<Page> pageIterator = readPages(serde, sliceOutput.slice().getInput());
    assertPageEquals(types, pageIterator.next(), expectedPage);
    assertPageEquals(types, pageIterator.next(), expectedPage);
    assertPageEquals(types, pageIterator.next(), expectedPage);
    assertFalse(pageIterator.hasNext());
}
Also used : Type(com.facebook.presto.common.type.Type) PagesSerde(com.facebook.presto.spi.page.PagesSerde) Block(com.facebook.presto.common.block.Block) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

PagesSerde (com.facebook.presto.spi.page.PagesSerde)11 Page (com.facebook.presto.common.Page)4 SpillCipher (com.facebook.presto.spi.spiller.SpillCipher)3 Block (com.facebook.presto.common.block.Block)2 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 Type (com.facebook.presto.common.type.Type)2 PrestoException (com.facebook.presto.spi.PrestoException)2 SerializedPage (com.facebook.presto.spi.page.SerializedPage)2 PrestoThriftPage (com.facebook.presto.thrift.api.udf.PrestoThriftPage)2 ThriftUdfPage (com.facebook.presto.thrift.api.udf.ThriftUdfPage)2 DynamicSliceOutput (io.airlift.slice.DynamicSliceOutput)2 Test (org.testng.annotations.Test)2 SqlFunctionResult (com.facebook.presto.common.function.SqlFunctionResult)1 DataSink (com.facebook.presto.common.io.DataSink)1 TestingPagesSerdeFactory (com.facebook.presto.execution.buffer.TestingPagesSerdeFactory)1 GrpcSerializedPage (com.facebook.presto.grpc.udf.GrpcSerializedPage)1 HiveCompressionCodec (com.facebook.presto.hive.HiveCompressionCodec)1 DeflateCompressor (com.facebook.presto.orc.zlib.DeflateCompressor)1 InflateDecompressor (com.facebook.presto.orc.zlib.InflateDecompressor)1 ZstdJniCompressor (com.facebook.presto.orc.zstd.ZstdJniCompressor)1