Search in sources :

Example 1 with PagesSerde

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

the class TestPagesSerde method serializedSize.

private static int serializedSize(List<? extends Type> types, Page expectedPage) {
    PagesSerde serde = new TestingPagesSerdeFactory().createPagesSerde();
    DynamicSliceOutput sliceOutput = new DynamicSliceOutput(1024);
    writePages(serde, sliceOutput, expectedPage);
    Slice slice = sliceOutput.slice();
    Iterator<Page> pageIterator = readPages(serde, slice.getInput());
    if (pageIterator.hasNext()) {
        assertPageEquals(types, pageIterator.next(), expectedPage);
    } else {
        assertEquals(expectedPage.getPositionCount(), 0);
    }
    assertFalse(pageIterator.hasNext());
    return slice.length();
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) Slice(io.airlift.slice.Slice) DynamicSliceOutput(io.airlift.slice.DynamicSliceOutput) Page(com.facebook.presto.common.Page)

Example 2 with PagesSerde

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

the class FileSingleStreamSpillerFactory method create.

@Override
public SingleStreamSpiller create(List<Type> types, SpillContext spillContext, LocalMemoryContext memoryContext) {
    Optional<SpillCipher> spillCipher = Optional.empty();
    if (spillEncryptionEnabled) {
        spillCipher = Optional.of(new AesSpillCipher());
    }
    PagesSerde serde = serdeFactory.createPagesSerdeForSpill(spillCipher);
    return new FileSingleStreamSpiller(serde, executor, getNextSpillPath(), spillerStats, spillContext, memoryContext, spillCipher);
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) SpillCipher(com.facebook.presto.spi.spiller.SpillCipher)

Example 3 with PagesSerde

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

the class TempStorageSingleStreamSpillerFactory method create.

@Override
public SingleStreamSpiller create(List<Type> types, SpillContext spillContext, LocalMemoryContext memoryContext) {
    Optional<SpillCipher> spillCipher = Optional.empty();
    if (spillEncryptionEnabled) {
        spillCipher = Optional.of(new AesSpillCipher());
    }
    PagesSerde serde = serdeFactory.createPagesSerdeForSpill(spillCipher);
    return new TempStorageSingleStreamSpiller(tempStorageManager.getTempStorage(tempStorageName), serde, executor, spillerStats, spillContext, memoryContext, spillCipher);
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) SpillCipher(com.facebook.presto.spi.spiller.SpillCipher)

Example 4 with PagesSerde

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

the class ThriftSqlFunctionExecutor method toSqlFunctionResult.

private SqlFunctionResult toSqlFunctionResult(ThriftUdfResult result, Type returnType) {
    ThriftUdfPage page = result.getResult();
    switch(page.getPageFormat()) {
        case PRESTO_THRIFT:
            return new SqlFunctionResult(getOnlyElement(page.getThriftPage().getThriftBlocks()).toBlock(returnType), result.getUdfStats().getTotalCpuTimeMs());
        case PRESTO_SERIALIZED:
            checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            return new SqlFunctionResult(pagesSerde.deserialize(page.getPrestoPage().toSerializedPage()).getBlock(0), result.getUdfStats().getTotalCpuTimeMs());
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", page.getPageFormat()));
    }
}
Also used : PagesSerde(com.facebook.presto.spi.page.PagesSerde) ThriftUdfPage(com.facebook.presto.thrift.api.udf.ThriftUdfPage) SqlFunctionResult(com.facebook.presto.common.function.SqlFunctionResult)

Example 5 with PagesSerde

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

the class ThriftSqlFunctionExecutor method buildThriftPage.

private ThriftUdfPage buildThriftPage(RemoteScalarFunctionImplementation functionImplementation, Page input, List<Integer> channels, List<Type> argumentTypes) {
    ThriftUdfPageFormat pageFormat = executionConfigs.get(functionImplementation.getLanguage()).getThriftPageFormat();
    Block[] blocks = new Block[channels.size()];
    for (int i = 0; i < channels.size(); i++) {
        blocks[i] = input.getBlock(channels.get(i));
    }
    switch(pageFormat) {
        case PRESTO_THRIFT:
            ImmutableList.Builder<PrestoThriftBlock> thriftBlocks = ImmutableList.builder();
            for (int i = 0; i < blocks.length; i++) {
                thriftBlocks.add(PrestoThriftBlock.fromBlock(blocks[i], argumentTypes.get(i)));
            }
            return thriftPage(new PrestoThriftPage(thriftBlocks.build(), input.getPositionCount()));
        case PRESTO_SERIALIZED:
            checkState(blockEncodingSerde != null, "blockEncodingSerde not set");
            PagesSerde pagesSerde = new PagesSerde(blockEncodingSerde, Optional.empty(), Optional.empty(), Optional.empty());
            return prestoPage(pagesSerde.serialize(wrapBlocksWithoutCopy(input.getPositionCount(), blocks)));
        default:
            throw new IllegalArgumentException(format("Unknown page format: %s", pageFormat));
    }
}
Also used : PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) PrestoThriftPage(com.facebook.presto.thrift.api.udf.PrestoThriftPage) PagesSerde(com.facebook.presto.spi.page.PagesSerde) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) PrestoThriftBlock(com.facebook.presto.thrift.api.datatypes.PrestoThriftBlock) Block(com.facebook.presto.common.block.Block) ThriftUdfPageFormat(com.facebook.presto.thrift.api.udf.ThriftUdfPageFormat)

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