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();
}
Aggregations