use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class TestUnnesterUtil method buildExpectedUnnestedArrayOfRowBlock.
private static Block[] buildExpectedUnnestedArrayOfRowBlock(Block block, List<Type> rowTypes, int[] maxCardinalities, int totalEntries) {
ColumnarArray columnarArray = ColumnarArray.toColumnarArray(block);
Block elementBlock = columnarArray.getElementsBlock();
ColumnarRow columnarRow = ColumnarRow.toColumnarRow(elementBlock);
int fieldCount = columnarRow.getFieldCount();
Block[] blocks = new Block[fieldCount];
int positionCount = block.getPositionCount();
for (int i = 0; i < fieldCount; i++) {
BlockBuilder blockBuilder = rowTypes.get(i).createBlockBuilder(null, totalEntries);
int nullRowsEncountered = 0;
for (int j = 0; j < positionCount; j++) {
int rowBlockIndex = columnarArray.getOffset(j);
int cardinality = columnarArray.getLength(j);
for (int k = 0; k < cardinality; k++) {
if (columnarRow.isNull(rowBlockIndex + k)) {
blockBuilder.appendNull();
nullRowsEncountered++;
} else {
rowTypes.get(i).appendTo(columnarRow.getField(i), rowBlockIndex + k - nullRowsEncountered, blockBuilder);
}
}
int maxCardinality = maxCardinalities[j];
for (int k = cardinality; k < maxCardinality; k++) {
blockBuilder.appendNull();
}
}
blocks[i] = blockBuilder.build();
}
return blocks;
}
use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class TestUnnesterUtil method buildExpectedUnnestedArrayBlock.
private static Block buildExpectedUnnestedArrayBlock(Block block, Type type, int[] maxCardinalities, int totalEntries) {
ColumnarArray columnarArray = ColumnarArray.toColumnarArray(block);
Block elementBlock = columnarArray.getElementsBlock();
BlockBuilder blockBuilder = type.createBlockBuilder(null, totalEntries);
int positionCount = block.getPositionCount();
int elementBlockPosition = 0;
for (int i = 0; i < positionCount; i++) {
int cardinality = columnarArray.getLength(i);
for (int j = 0; j < cardinality; j++) {
type.appendTo(elementBlock, elementBlockPosition++, blockBuilder);
}
int maxCardinality = maxCardinalities[i];
for (int j = cardinality; j < maxCardinality; j++) {
blockBuilder.appendNull();
}
}
return blockBuilder.build();
}
use of com.facebook.presto.common.block.ColumnarArray in project presto by prestodb.
the class ArrayBlockEncodingBuffer method setupDecodedBlockAndMapPositions.
@Override
protected void setupDecodedBlockAndMapPositions(DecodedBlockNode decodedBlockNode, int partitionBufferCapacity, double decodedBlockPageSizeFraction) {
requireNonNull(decodedBlockNode, "decodedBlockNode is null");
decodedBlockNode = mapPositionsToNestedBlock(decodedBlockNode);
ColumnarArray columnarArray = (ColumnarArray) decodedBlockNode.getDecodedBlock();
decodedBlock = columnarArray.getNullCheckBlock();
long estimatedSerializedSizeInBytes = decodedBlockNode.getEstimatedSerializedSizeInBytes();
long childrenEstimatedSerializedSizeInBytes = decodedBlockNode.getChildren().get(0).getEstimatedSerializedSizeInBytes();
double targetBufferSize = partitionBufferCapacity * decodedBlockPageSizeFraction * (estimatedSerializedSizeInBytes - childrenEstimatedSerializedSizeInBytes) / estimatedSerializedSizeInBytes;
setEstimatedNullsBufferMaxCapacity(getEstimatedBufferMaxCapacity(targetBufferSize, Byte.BYTES, POSITION_SIZE));
estimatedOffsetBufferMaxCapacity = getEstimatedBufferMaxCapacity(targetBufferSize, Integer.BYTES, POSITION_SIZE);
populateNestedPositions(columnarArray);
valuesBuffers.setupDecodedBlockAndMapPositions(decodedBlockNode.getChildren().get(0), partitionBufferCapacity, decodedBlockPageSizeFraction * childrenEstimatedSerializedSizeInBytes / estimatedSerializedSizeInBytes);
}
Aggregations