Search in sources :

Example 1 with UncheckedStackArrayAllocator

use of com.facebook.presto.operator.UncheckedStackArrayAllocator 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);
}
Also used : Closer(com.google.common.io.Closer) BlockFlattener(com.facebook.presto.common.block.BlockFlattener) UncheckedStackArrayAllocator(com.facebook.presto.operator.UncheckedStackArrayAllocator) MapBlock.fromKeyValueBlock(com.facebook.presto.common.block.MapBlock.fromKeyValueBlock) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) OptimizedPartitionedOutputOperator.decodeBlock(com.facebook.presto.operator.repartition.OptimizedPartitionedOutputOperator.decodeBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) BlockAssertions.createRandomSmallintsBlock(com.facebook.presto.block.BlockAssertions.createRandomSmallintsBlock) ArrayBlock.fromElementBlock(com.facebook.presto.common.block.ArrayBlock.fromElementBlock) BlockAssertions.createAllNullsBlock(com.facebook.presto.block.BlockAssertions.createAllNullsBlock) BlockAssertions.createRandomBooleansBlock(com.facebook.presto.block.BlockAssertions.createRandomBooleansBlock) BlockAssertions.createRandomStringBlock(com.facebook.presto.block.BlockAssertions.createRandomStringBlock) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) BlockAssertions.createRandomShortDecimalsBlock(com.facebook.presto.block.BlockAssertions.createRandomShortDecimalsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) BlockAssertions.wrapBlock(com.facebook.presto.block.BlockAssertions.wrapBlock) BlockSerdeUtil.readBlock(com.facebook.presto.common.block.BlockSerdeUtil.readBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createRandomIntsBlock(com.facebook.presto.block.BlockAssertions.createRandomIntsBlock) Block(com.facebook.presto.common.block.Block) BlockAssertions.createRandomLongDecimalsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongDecimalsBlock) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Example 2 with UncheckedStackArrayAllocator

use of com.facebook.presto.operator.UncheckedStackArrayAllocator 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);
    }
}
Also used : BlockFlattener(com.facebook.presto.common.block.BlockFlattener) Closer(com.google.common.io.Closer) UncheckedStackArrayAllocator(com.facebook.presto.operator.UncheckedStackArrayAllocator) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException)

Aggregations

BlockFlattener (com.facebook.presto.common.block.BlockFlattener)2 UncheckedStackArrayAllocator (com.facebook.presto.operator.UncheckedStackArrayAllocator)2 Closer (com.google.common.io.Closer)2 IOException (java.io.IOException)2 UncheckedIOException (java.io.UncheckedIOException)2 BlockAssertions.createAllNullsBlock (com.facebook.presto.block.BlockAssertions.createAllNullsBlock)1 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)1 BlockAssertions.createRandomBooleansBlock (com.facebook.presto.block.BlockAssertions.createRandomBooleansBlock)1 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)1 BlockAssertions.createRandomIntsBlock (com.facebook.presto.block.BlockAssertions.createRandomIntsBlock)1 BlockAssertions.createRandomLongDecimalsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongDecimalsBlock)1 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)1 BlockAssertions.createRandomShortDecimalsBlock (com.facebook.presto.block.BlockAssertions.createRandomShortDecimalsBlock)1 BlockAssertions.createRandomSmallintsBlock (com.facebook.presto.block.BlockAssertions.createRandomSmallintsBlock)1 BlockAssertions.createRandomStringBlock (com.facebook.presto.block.BlockAssertions.createRandomStringBlock)1 BlockAssertions.createStringsBlock (com.facebook.presto.block.BlockAssertions.createStringsBlock)1 BlockAssertions.wrapBlock (com.facebook.presto.block.BlockAssertions.wrapBlock)1 ArrayBlock.fromElementBlock (com.facebook.presto.common.block.ArrayBlock.fromElementBlock)1 Block (com.facebook.presto.common.block.Block)1 BlockSerdeUtil.readBlock (com.facebook.presto.common.block.BlockSerdeUtil.readBlock)1