Search in sources :

Example 6 with SelectedPositions

use of com.facebook.presto.operator.project.SelectedPositions in project presto by prestodb.

the class OptimizedTypedSet method getBlock.

/**
 * Build and return the block representing this set
 */
public Block getBlock() {
    if (size == 0) {
        return elementType.createBlockBuilder(null, 0).build();
    }
    if (currentBlockIndex == 0) {
        // Just one block. Return a DictionaryBlock
        Block block = blocks[currentBlockIndex];
        SelectedPositions selectedPositions = getPositionsForBlocks().get(currentBlockIndex);
        return new DictionaryBlock(selectedPositions.getOffset(), selectedPositions.size(), block, selectedPositions.getPositions(), false, DictionaryId.randomDictionaryId());
    }
    Block firstBlock = blocks[0];
    BlockBuilder blockBuilder = elementType.createBlockBuilder(null, size, toIntExact(firstBlock.getApproximateRegionLogicalSizeInBytes(0, firstBlock.getPositionCount()) / max(1, toIntExact(firstBlock.getPositionCount()))));
    for (int i = 0; i <= currentBlockIndex; i++) {
        Block block = blocks[i];
        SelectedPositions selectedPositions = getPositionsForBlocks().get(i);
        int positionCount = selectedPositions.size();
        if (!selectedPositions.isList()) {
            if (positionCount == block.getPositionCount()) {
                return block;
            } else {
                return block.getRegion(selectedPositions.getOffset(), positionCount);
            }
        }
        int[] positions = selectedPositions.getPositions();
        for (int j = 0; j < positionCount; j++) {
            // offset is always 0
            int position = positions[j];
            if (block.isNull(position)) {
                blockBuilder.appendNull();
            } else {
                elementType.appendTo(block, position, blockBuilder);
            }
        }
    }
    return blockBuilder.build();
}
Also used : SelectedPositions(com.facebook.presto.operator.project.SelectedPositions) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

SelectedPositions (com.facebook.presto.operator.project.SelectedPositions)6 Block (com.facebook.presto.common.block.Block)4 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)4 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)3 MethodDefinition (com.facebook.presto.bytecode.MethodDefinition)3 Parameter (com.facebook.presto.bytecode.Parameter)3 Scope (com.facebook.presto.bytecode.Scope)3 Variable (com.facebook.presto.bytecode.Variable)3 ForLoop (com.facebook.presto.bytecode.control.ForLoop)3 IfStatement (com.facebook.presto.bytecode.control.IfStatement)3 Page (com.facebook.presto.common.Page)3 Logger (com.facebook.airlift.log.Logger)2 FINAL (com.facebook.presto.bytecode.Access.FINAL)2 PRIVATE (com.facebook.presto.bytecode.Access.PRIVATE)2 PUBLIC (com.facebook.presto.bytecode.Access.PUBLIC)2 Access.a (com.facebook.presto.bytecode.Access.a)2 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)2 CallSiteBinder (com.facebook.presto.bytecode.CallSiteBinder)2 ClassDefinition (com.facebook.presto.bytecode.ClassDefinition)2 FieldDefinition (com.facebook.presto.bytecode.FieldDefinition)2