Search in sources :

Example 11 with SerializedPage

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

the class SpoolingOutputBuffer method getPagesFromStorage.

private ListenableFuture<List<SerializedPage>> getPagesFromStorage(ImmutableList.Builder<SerializedPage> resultBuilder, Iterator<HandleInfo> handleIterator, TempStorageHandle handle, GetTracker getTracker) {
    long maxBytes = getTracker.getMaxSize().toBytes();
    long bytes = getTracker.getBytes();
    long pageCount = getTracker.getPageCount();
    try (SliceInput inputStream = new InputStreamSliceInput(tempStorage.open(tempDataOperationContext, handle))) {
        Iterator<SerializedPage> serializedPages = readSerializedPages(inputStream);
        advance(serializedPages, getTracker.getStartPage());
        while (serializedPages.hasNext()) {
            SerializedPage page = serializedPages.next();
            long bytesRead = bytes;
            bytes += page.getRetainedSizeInBytes();
            if (pageCount != 0 && bytes > maxBytes) {
                getTracker.update(bytesRead, pageCount);
                return immediateFuture(resultBuilder.build());
            }
            resultBuilder.add(page);
            pageCount++;
        }
        getTracker.update(bytes, pageCount);
        if (!handleIterator.hasNext()) {
            return immediateFuture(resultBuilder.build());
        }
        return transformAsync(handleIterator.next().getHandleFuture(), input -> getPagesFromStorage(resultBuilder, handleIterator, input, getTracker), executor);
    } catch (IOException e) {
        throw new PrestoException(SPOOLING_STORAGE_ERROR, "Failed to read file from TempStorage", e);
    }
}
Also used : InputStreamSliceInput(io.airlift.slice.InputStreamSliceInput) SerializedPage(com.facebook.presto.spi.page.SerializedPage) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) SliceInput(io.airlift.slice.SliceInput) InputStreamSliceInput(io.airlift.slice.InputStreamSliceInput)

Example 12 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage 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 13 with SerializedPage

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

the class ExchangeOperator method getOutput.

@Override
public Page getOutput() {
    SerializedPage page = exchangeClient.pollPage();
    if (page == null) {
        return null;
    }
    operatorContext.recordRawInput(page.getSizeInBytes(), page.getPositionCount());
    Page deserializedPage = serde.deserialize(page);
    operatorContext.recordProcessedInput(deserializedPage.getSizeInBytes(), page.getPositionCount());
    return deserializedPage;
}
Also used : SerializedPage(com.facebook.presto.spi.page.SerializedPage) Page(com.facebook.presto.common.Page) SerializedPage(com.facebook.presto.spi.page.SerializedPage)

Example 14 with SerializedPage

use of com.facebook.presto.spi.page.SerializedPage 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 15 with SerializedPage

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

the class TestThriftBufferResult method testThriftSerializedPage.

@Test
public void testThriftSerializedPage() {
    SerializedPage serializedPage = new SerializedPage(EMPTY_SLICE, PageCodecMarker.none(), 0, 0, 0);
    ThriftSerializedPage thriftSerializedPage = new ThriftSerializedPage((serializedPage));
    SerializedPage newSerializedPage = thriftSerializedPage.toSerializedPage();
    assertEquals(serializedPage, newSerializedPage);
}
Also used : SerializedPage(com.facebook.presto.spi.page.SerializedPage) Test(org.testng.annotations.Test)

Aggregations

SerializedPage (com.facebook.presto.spi.page.SerializedPage)18 Page (com.facebook.presto.common.Page)8 ImmutableList (com.google.common.collect.ImmutableList)7 PrestoException (com.facebook.presto.spi.PrestoException)4 InputStreamSliceInput (io.airlift.slice.InputStreamSliceInput)4 InputStream (java.io.InputStream)3 List (java.util.List)3 BlockEncodingManager (com.facebook.presto.common.block.BlockEncodingManager)2 PagesSerde (com.facebook.presto.spi.page.PagesSerde)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 IOException (java.io.IOException)2 URI (java.net.URI)2 Test (org.testng.annotations.Test)2 BoundedExecutor (com.facebook.airlift.concurrent.BoundedExecutor)1 MoreFutures.addTimeout (com.facebook.airlift.concurrent.MoreFutures.addTimeout)1 APPLICATION_THRIFT_BINARY (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_BINARY)1 APPLICATION_THRIFT_COMPACT (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_COMPACT)1 APPLICATION_THRIFT_FB_COMPACT (com.facebook.airlift.http.client.thrift.ThriftRequestUtils.APPLICATION_THRIFT_FB_COMPACT)1 AsyncResponseHandler.bindAsyncResponse (com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse)1 Codec (com.facebook.airlift.json.Codec)1