Search in sources :

Example 6 with ColumnarArray

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

Example 7 with ColumnarArray

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

Example 8 with ColumnarArray

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

Aggregations

ColumnarArray (com.facebook.presto.common.block.ColumnarArray)8 Block (com.facebook.presto.common.block.Block)5 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 ColumnarArray.toColumnarArray (com.facebook.presto.common.block.ColumnarArray.toColumnarArray)2 ColumnarMap (com.facebook.presto.common.block.ColumnarMap)2 ColumnarRow (com.facebook.presto.common.block.ColumnarRow)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 BlockLease (com.facebook.presto.common.block.BlockLease)1 MapBlock (com.facebook.presto.common.block.MapBlock)1 RowBlock (com.facebook.presto.common.block.RowBlock)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 MapType (com.facebook.presto.common.type.MapType)1 RowType (com.facebook.presto.common.type.RowType)1 Type (com.facebook.presto.common.type.Type)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1