Search in sources :

Example 6 with ColumnarRow

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));
    }
}
Also used : ColumnarRow.toColumnarRow(com.facebook.presto.common.block.ColumnarRow.toColumnarRow) ColumnarRow(com.facebook.presto.common.block.ColumnarRow) RepetitionLevelIterable(com.facebook.presto.parquet.writer.levels.RepetitionLevelIterable) Block(com.facebook.presto.common.block.Block) DefinitionLevelIterable(com.facebook.presto.parquet.writer.levels.DefinitionLevelIterable)

Example 7 with ColumnarRow

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);
}
Also used : ColumnarRow(com.facebook.presto.common.block.ColumnarRow)

Example 8 with ColumnarRow

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;
}
Also used : ColumnarRow(com.facebook.presto.common.block.ColumnarRow) ColumnarArray(com.facebook.presto.common.block.ColumnarArray) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

ColumnarRow (com.facebook.presto.common.block.ColumnarRow)8 Block (com.facebook.presto.common.block.Block)5 ColumnarRow.toColumnarRow (com.facebook.presto.common.block.ColumnarRow.toColumnarRow)5 ColumnarArray (com.facebook.presto.common.block.ColumnarArray)2 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)2 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)2 ColumnarTestUtils.assertBlock (com.facebook.presto.block.ColumnarTestUtils.assertBlock)1 ColumnarTestUtils.createTestDictionaryBlock (com.facebook.presto.block.ColumnarTestUtils.createTestDictionaryBlock)1 ColumnarTestUtils.createTestRleBlock (com.facebook.presto.block.ColumnarTestUtils.createTestRleBlock)1 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 BlockLease (com.facebook.presto.common.block.BlockLease)1 ColumnarMap (com.facebook.presto.common.block.ColumnarMap)1 MapBlock (com.facebook.presto.common.block.MapBlock)1 RowBlock (com.facebook.presto.common.block.RowBlock)1 DefinitionLevelIterable (com.facebook.presto.parquet.writer.levels.DefinitionLevelIterable)1 RepetitionLevelIterable (com.facebook.presto.parquet.writer.levels.RepetitionLevelIterable)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableList (com.google.common.collect.ImmutableList)1