use of com.facebook.presto.common.block.BlockFlattener in project presto by prestodb.
the class TestBlockEncodingBuffers method assertSerialized.
private static void assertSerialized(Type type, Block block, int[] expectedRowSizes) {
Closer blockLeaseCloser = Closer.create();
BlockFlattener flattener = new BlockFlattener(new UncheckedStackArrayAllocator());
DecodedBlockNode decodedBlock = decodeBlock(flattener, blockLeaseCloser, block);
BlockEncodingBuffer buffers = createBlockEncodingBuffers(decodedBlock, new UncheckedStackArrayAllocator(1000), false);
int[] positions = IntStream.range(0, block.getPositionCount() / 2).toArray();
copyPositions(decodedBlock, buffers, positions, expectedRowSizes);
positions = IntStream.range(block.getPositionCount() / 2, block.getPositionCount()).toArray();
copyPositions(decodedBlock, buffers, positions, expectedRowSizes);
assertBlockEquals(type, serialize(buffers), block);
buffers.resetBuffers();
positions = IntStream.range(0, block.getPositionCount()).filter(n -> n % 2 == 0).toArray();
Block expectedBlock = block.copyPositions(positions, 0, positions.length);
copyPositions(decodedBlock, buffers, positions, expectedRowSizes);
try {
blockLeaseCloser.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
assertBlockEquals(type, serialize(buffers), expectedBlock);
}
use of com.facebook.presto.common.block.BlockFlattener in project presto by prestodb.
the class TestBlockEncodingBuffers method assertEstimatedBufferMaxCapacities.
private void assertEstimatedBufferMaxCapacities(Page page, List<Object> expectedMaxBufferCapacities) {
int channelCount = page.getChannelCount();
int positionCount = page.getPositionCount();
DecodedBlockNode[] decodedBlocks = new DecodedBlockNode[channelCount];
BlockFlattener flattener = new BlockFlattener(new UncheckedStackArrayAllocator());
Closer blockLeaseCloser = Closer.create();
long estimatedSerializedPageSize = 0;
for (int i = 0; i < decodedBlocks.length; i++) {
decodedBlocks[i] = decodeBlock(flattener, blockLeaseCloser, page.getBlock(i));
estimatedSerializedPageSize += decodedBlocks[i].getEstimatedSerializedSizeInBytes();
}
int[] positions = IntStream.range(0, positionCount).toArray();
for (int i = 0; i < decodedBlocks.length; i++) {
BlockEncodingBuffer buffer = createBlockEncodingBuffers(decodedBlocks[i], new UncheckedStackArrayAllocator(1000), false);
buffer.setupDecodedBlocksAndPositions(decodedBlocks[i], positions, positionCount, (int) estimatedSerializedPageSize, estimatedSerializedPageSize);
assertEstimatedBufferMaxCapacity(buffer, (List<Object>) expectedMaxBufferCapacities.get(i));
}
try {
blockLeaseCloser.close();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations