use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class StructColumnWriter method writeBlock.
@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
ColumnarRow columnarRow = toColumnarRow(columnChunk.getBlock());
checkArgument(columnarRow.getFieldCount() == columnWriters.size(), "ColumnarRow field size %s is not equal to columnWriters size %s", columnarRow.getFieldCount(), columnWriters.size());
List<DefinitionLevelIterable> defLevelIterables = ImmutableList.<DefinitionLevelIterable>builder().addAll(columnChunk.getDefinitionLevelIterables()).add(DefinitionLevelIterables.of(columnarRow, maxDefinitionLevel)).build();
List<RepetitionLevelIterable> repLevelIterables = ImmutableList.<RepetitionLevelIterable>builder().addAll(columnChunk.getRepetitionLevelIterables()).add(RepetitionLevelIterables.of(columnChunk.getBlock())).build();
for (int i = 0; i < columnWriters.size(); ++i) {
ColumnWriter columnWriter = columnWriters.get(i);
Block block = columnarRow.getField(i);
columnWriter.writeBlock(new ColumnChunk(block, defLevelIterables, repLevelIterables));
}
}
use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.
the class RowBlockEncodingBuffer method setupDecodedBlockAndMapPositions.
@Override
protected void setupDecodedBlockAndMapPositions(DecodedBlockNode decodedBlockNode, int partitionBufferCapacity, double decodedBlockPageSizeFraction) {
requireNonNull(decodedBlockNode, "decodedBlockNode is null");
decodedBlockNode = mapPositionsToNestedBlock(decodedBlockNode);
ColumnarRow columnarRow = (ColumnarRow) decodedBlockNode.getDecodedBlock();
decodedBlock = columnarRow.getNullCheckBlock();
populateNestedPositions(columnarRow);
long estimatedSerializedSizeInBytes = decodedBlockNode.getEstimatedSerializedSizeInBytes();
long childrenEstimatedSerializedSizeInBytes = 0;
for (int i = 0; i < fieldBuffers.length; i++) {
DecodedBlockNode childDecodedBlockNode = decodedBlockNode.getChildren().get(i);
long childEstimatedSerializedSizeInBytes = childDecodedBlockNode.getEstimatedSerializedSizeInBytes();
childrenEstimatedSerializedSizeInBytes += childEstimatedSerializedSizeInBytes;
fieldBuffers[i].setupDecodedBlockAndMapPositions(childDecodedBlockNode, partitionBufferCapacity, decodedBlockPageSizeFraction * childEstimatedSerializedSizeInBytes / estimatedSerializedSizeInBytes);
}
double targetBufferSize = partitionBufferCapacity * decodedBlockPageSizeFraction * (estimatedSerializedSizeInBytes - childrenEstimatedSerializedSizeInBytes) / estimatedSerializedSizeInBytes;
setEstimatedNullsBufferMaxCapacity(getEstimatedBufferMaxCapacity(targetBufferSize, Byte.BYTES, POSITION_SIZE));
estimatedOffsetBufferMaxCapacity = getEstimatedBufferMaxCapacity(targetBufferSize, Integer.BYTES, POSITION_SIZE);
}
use of com.facebook.presto.common.block.ColumnarRow 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;
}
Aggregations