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);
}
}
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();
}
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;
}
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");
}
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);
}
Aggregations