Search in sources :

Example 6 with IntArrayBlockBuilder

use of com.facebook.presto.common.block.IntArrayBlockBuilder in project presto by prestodb.

the class TestBlockBigArray method testRetainedSizeWithOverlappingBlocks.

@Test
public void testRetainedSizeWithOverlappingBlocks() {
    int entries = 123;
    BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, entries);
    for (int i = 0; i < entries; i++) {
        blockBuilder.writeInt(i);
    }
    Block block = blockBuilder.build();
    // Verify we do not over count
    int arraySize = 456;
    int blocks = 7890;
    BlockBigArray blockBigArray = new BlockBigArray();
    blockBigArray.ensureCapacity(arraySize);
    for (int i = 0; i < blocks; i++) {
        blockBigArray.set(i % arraySize, block.getRegion(0, entries));
    }
    ReferenceCountMap referenceCountMap = new ReferenceCountMap();
    referenceCountMap.incrementAndGet(block);
    long expectedSize = ClassLayout.parseClass(BlockBigArray.class).instanceSize() + referenceCountMap.sizeOf() + (new ObjectBigArray()).sizeOf() + block.getRetainedSizeInBytes() + (arraySize - 1) * ClassLayout.parseClass(block.getClass()).instanceSize();
    assertEquals(blockBigArray.sizeOf(), expectedSize);
}
Also used : IntArrayBlockBuilder(com.facebook.presto.common.block.IntArrayBlockBuilder) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) IntArrayBlockBuilder(com.facebook.presto.common.block.IntArrayBlockBuilder) Test(org.testng.annotations.Test)

Aggregations

IntArrayBlockBuilder (com.facebook.presto.common.block.IntArrayBlockBuilder)6 Test (org.testng.annotations.Test)4 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)3 Page (com.facebook.presto.common.Page)1 Block (com.facebook.presto.common.block.Block)1 Slice (io.airlift.slice.Slice)1