Search in sources :

Example 1 with ColumnarRow

use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.

the class StructColumnWriter method writeBlock.

@Override
public long writeBlock(Block block) {
    checkState(!closed);
    checkArgument(block.getPositionCount() > 0, "Block is empty");
    ColumnarRow columnarRow = toColumnarRow(block);
    return writeColumnarRow(columnarRow);
}
Also used : ColumnarRow.toColumnarRow(com.facebook.presto.common.block.ColumnarRow.toColumnarRow) ColumnarRow(com.facebook.presto.common.block.ColumnarRow)

Example 2 with ColumnarRow

use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.

the class MultimapAggregationStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, MultimapAggregationState state) {
    state.reset();
    ColumnarRow columnarRow = toColumnarRow(arrayType.getObject(block, index));
    Block keys = columnarRow.getField(KEY_CHANNEL);
    Block values = columnarRow.getField(VALUE_CHANNEL);
    for (int i = 0; i < columnarRow.getPositionCount(); i++) {
        state.add(keys, values, i);
    }
}
Also used : ColumnarRow.toColumnarRow(com.facebook.presto.common.block.ColumnarRow.toColumnarRow) ColumnarRow(com.facebook.presto.common.block.ColumnarRow) Block(com.facebook.presto.common.block.Block)

Example 3 with ColumnarRow

use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.

the class OptimizedPartitionedOutputOperator method decodeBlock.

/**
 * Flatten the block and convert the nested-typed block into ColumnarArray/Map/Row.
 * For performance considerations we decode the block only once for each block instead of for each batch.
 *
 * @return A tree structure that contains the decoded block
 */
@VisibleForTesting
static DecodedBlockNode decodeBlock(BlockFlattener flattener, Closer blockLeaseCloser, Block block) {
    BlockLease lease = flattener.flatten(block);
    blockLeaseCloser.register(lease::close);
    Block decodedBlock = lease.get();
    long estimatedSizeInBytes = decodedBlock.getLogicalSizeInBytes();
    if (decodedBlock instanceof ArrayBlock) {
        ColumnarArray columnarArray = ColumnarArray.toColumnarArray(decodedBlock);
        Block childBlock = columnarArray.getElementsBlock();
        return new DecodedBlockNode(columnarArray, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, childBlock)), columnarArray.getRetainedSizeInBytes(), estimatedSizeInBytes);
    }
    if (decodedBlock instanceof MapBlock) {
        ColumnarMap columnarMap = ColumnarMap.toColumnarMap(decodedBlock);
        Block keyBlock = columnarMap.getKeysBlock();
        Block valueBlock = columnarMap.getValuesBlock();
        return new DecodedBlockNode(columnarMap, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, keyBlock), decodeBlock(flattener, blockLeaseCloser, valueBlock)), columnarMap.getRetainedSizeInBytes(), estimatedSizeInBytes);
    }
    if (decodedBlock instanceof RowBlock) {
        ColumnarRow columnarRow = ColumnarRow.toColumnarRow(decodedBlock);
        ImmutableList.Builder<DecodedBlockNode> children = ImmutableList.builder();
        for (int i = 0; i < columnarRow.getFieldCount(); i++) {
            Block childBlock = columnarRow.getField(i);
            children.add(decodeBlock(flattener, blockLeaseCloser, childBlock));
        }
        return new DecodedBlockNode(columnarRow, children.build(), columnarRow.getRetainedSizeInBytes(), estimatedSizeInBytes);
    }
    if (decodedBlock instanceof DictionaryBlock) {
        Block dictionary = ((DictionaryBlock) decodedBlock).getDictionary();
        return new DecodedBlockNode(decodedBlock, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, dictionary)), decodedBlock.getRetainedSizeInBytes(), estimatedSizeInBytes);
    }
    if (decodedBlock instanceof RunLengthEncodedBlock) {
        Block childBlock = ((RunLengthEncodedBlock) decodedBlock).getValue();
        return new DecodedBlockNode(decodedBlock, ImmutableList.of(decodeBlock(flattener, blockLeaseCloser, childBlock)), decodedBlock.getRetainedSizeInBytes(), estimatedSizeInBytes);
    }
    return new DecodedBlockNode(decodedBlock, ImmutableList.of(), block.getRetainedSizeInBytes(), estimatedSizeInBytes);
}
Also used : ColumnarArray(com.facebook.presto.common.block.ColumnarArray) BlockLease(com.facebook.presto.common.block.BlockLease) ArrayBlock(com.facebook.presto.common.block.ArrayBlock) ImmutableList(com.google.common.collect.ImmutableList) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) RowBlock(com.facebook.presto.common.block.RowBlock) ColumnarRow(com.facebook.presto.common.block.ColumnarRow) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) MapBlock(com.facebook.presto.common.block.MapBlock) RowBlock(com.facebook.presto.common.block.RowBlock) ArrayBlock(com.facebook.presto.common.block.ArrayBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) MapBlock(com.facebook.presto.common.block.MapBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with ColumnarRow

use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.

the class TestColumnarRow method assertColumnarRow.

private static <T> void assertColumnarRow(Block block, T[] expectedValues) {
    ColumnarRow columnarRow = toColumnarRow(block);
    assertEquals(columnarRow.getPositionCount(), expectedValues.length);
    for (int fieldId = 0; fieldId < FIELD_COUNT; fieldId++) {
        Block fieldBlock = columnarRow.getField(fieldId);
        int elementsPosition = 0;
        for (int position = 0; position < expectedValues.length; position++) {
            T expectedRow = expectedValues[position];
            assertEquals(columnarRow.isNull(position), expectedRow == null);
            if (expectedRow == null) {
                continue;
            }
            Object expectedElement = Array.get(expectedRow, fieldId);
            assertBlockPosition(fieldBlock, elementsPosition, expectedElement);
            elementsPosition++;
        }
    }
}
Also used : ColumnarRow.toColumnarRow(com.facebook.presto.common.block.ColumnarRow.toColumnarRow) ColumnarRow(com.facebook.presto.common.block.ColumnarRow) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) ColumnarTestUtils.createTestDictionaryBlock(com.facebook.presto.block.ColumnarTestUtils.createTestDictionaryBlock) ColumnarTestUtils.createTestRleBlock(com.facebook.presto.block.ColumnarTestUtils.createTestRleBlock) ColumnarTestUtils.assertBlock(com.facebook.presto.block.ColumnarTestUtils.assertBlock) Block(com.facebook.presto.common.block.Block)

Example 5 with ColumnarRow

use of com.facebook.presto.common.block.ColumnarRow in project presto by prestodb.

the class KeyAndBlockPositionValueStateSerializer method deserialize.

@Override
public void deserialize(Block block, int index, T state) {
    ColumnarRow columnarRow = toColumnarRow(block);
    state.setFirstNull(BOOLEAN.getBoolean(columnarRow.getField(0), index));
    state.setSecondNull(BOOLEAN.getBoolean(columnarRow.getField(1), index));
    if (!state.isFirstNull()) {
        readFirstField(columnarRow.getField(2), index, state);
    }
    if (!state.isSecondNull()) {
        state.setSecondPosition(index);
        state.setSecondBlock(columnarRow.getField(3));
    }
}
Also used : ColumnarRow.toColumnarRow(com.facebook.presto.common.block.ColumnarRow.toColumnarRow) ColumnarRow(com.facebook.presto.common.block.ColumnarRow)

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