Search in sources :

Example 6 with DictionaryId

use of com.facebook.presto.spi.block.DictionaryId in project presto by prestodb.

the class Page method compact.

public void compact() {
    if (getRetainedSizeInBytes() <= getSizeInBytes()) {
        return;
    }
    for (int i = 0; i < blocks.length; i++) {
        Block block = blocks[i];
        if (block instanceof DictionaryBlock) {
            continue;
        }
        if (block.getSizeInBytes() < block.getRetainedSizeInBytes()) {
            // Copy the block to compact its size
            Block compactedBlock = block.copyRegion(0, block.getPositionCount());
            blocks[i] = compactedBlock;
        }
    }
    Map<DictionaryId, DictionaryBlockIndexes> dictionaryBlocks = getRelatedDictionaryBlocks();
    for (DictionaryBlockIndexes blockIndexes : dictionaryBlocks.values()) {
        List<DictionaryBlock> compactBlocks = compactRelatedBlocks(blockIndexes.getBlocks());
        List<Integer> indexes = blockIndexes.getIndexes();
        for (int i = 0; i < compactBlocks.size(); i++) {
            blocks[indexes.get(i)] = compactBlocks.get(i);
        }
    }
    long retainedSize = 0;
    for (Block block : blocks) {
        retainedSize += block.getRetainedSizeInBytes();
    }
    retainedSizeInBytes.set(retainedSize);
}
Also used : DictionaryId.randomDictionaryId(com.facebook.presto.spi.block.DictionaryId.randomDictionaryId) DictionaryId(com.facebook.presto.spi.block.DictionaryId) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock)

Aggregations

DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)6 DictionaryId (com.facebook.presto.spi.block.DictionaryId)6 DictionaryId.randomDictionaryId (com.facebook.presto.spi.block.DictionaryId.randomDictionaryId)6 Block (com.facebook.presto.spi.block.Block)5 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)2 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)2 LazyBlock (com.facebook.presto.spi.block.LazyBlock)2 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Page (com.facebook.presto.spi.Page)1 PageBuilder (com.facebook.presto.spi.PageBuilder)1 SliceArrayBlock (com.facebook.presto.spi.block.SliceArrayBlock)1 Slice (io.airlift.slice.Slice)1 Math.min (java.lang.Math.min)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Objects.requireNonNull (java.util.Objects.requireNonNull)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1