Search in sources :

Example 1 with ColumnarArray

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

the class ListColumnWriter method writeBlock.

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

Example 2 with ColumnarArray

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

the class ArrayColumnWriter method writeBlock.

@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
    ColumnarArray columnarArray = ColumnarArray.toColumnarArray(columnChunk.getBlock());
    elementWriter.writeBlock(new ColumnChunk(columnarArray.getElementsBlock(), ImmutableList.<DefinitionLevelIterable>builder().addAll(columnChunk.getDefinitionLevelIterables()).add(DefinitionLevelIterables.of(columnarArray, maxDefinitionLevel)).build(), ImmutableList.<RepetitionLevelIterable>builder().addAll(columnChunk.getRepetitionLevelIterables()).add(RepetitionLevelIterables.of(columnarArray, maxRepetitionLevel)).build()));
}
Also used : ColumnarArray(com.facebook.presto.common.block.ColumnarArray)

Example 3 with ColumnarArray

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

the class TestUnnesterUtil method calculateMaxCardinalities.

static int[] calculateMaxCardinalities(Page page, List<Type> replicatedTypes, List<Type> unnestTypes) {
    int positionCount = page.getPositionCount();
    int[] maxCardinalities = new int[positionCount];
    int replicatedChannelCount = replicatedTypes.size();
    int unnestChannelCount = unnestTypes.size();
    for (int i = 0; i < unnestChannelCount; i++) {
        Type type = unnestTypes.get(i);
        Block block = page.getBlock(replicatedChannelCount + i);
        assertTrue(type instanceof ArrayType || type instanceof MapType);
        if (type instanceof ArrayType) {
            ColumnarArray columnarArray = ColumnarArray.toColumnarArray(block);
            for (int j = 0; j < positionCount; j++) {
                maxCardinalities[j] = max(maxCardinalities[j], columnarArray.getLength(j));
            }
        } else if (type instanceof MapType) {
            ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
            for (int j = 0; j < positionCount; j++) {
                maxCardinalities[j] = max(maxCardinalities[j], columnarMap.getEntryCount(j));
            }
        } else {
            fail("expected an ArrayType or MapType, but found " + type);
        }
    }
    return maxCardinalities;
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) MapType(com.facebook.presto.common.type.MapType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) ColumnarArray(com.facebook.presto.common.block.ColumnarArray) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) Block(com.facebook.presto.common.block.Block) MapType(com.facebook.presto.common.type.MapType)

Example 4 with ColumnarArray

use of com.facebook.presto.common.block.ColumnarArray 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 5 with ColumnarArray

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

the class TestColumnarArray method assertColumnarArray.

private static <T> void assertColumnarArray(Block block, T[] expectedValues) {
    ColumnarArray columnarArray = toColumnarArray(block);
    assertEquals(columnarArray.getPositionCount(), expectedValues.length);
    Block elementsBlock = columnarArray.getElementsBlock();
    int elementsPosition = 0;
    for (int position = 0; position < expectedValues.length; position++) {
        T expectedArray = expectedValues[position];
        assertEquals(columnarArray.isNull(position), expectedArray == null);
        assertEquals(columnarArray.getLength(position), expectedArray == null ? 0 : Array.getLength(expectedArray));
        assertEquals(elementsPosition, columnarArray.getOffset(position));
        for (int i = 0; i < columnarArray.getLength(position); i++) {
            Object expectedElement = Array.get(expectedArray, i);
            assertBlockPosition(elementsBlock, elementsPosition, expectedElement);
            elementsPosition++;
        }
    }
}
Also used : ColumnarArray(com.facebook.presto.common.block.ColumnarArray) ColumnarArray.toColumnarArray(com.facebook.presto.common.block.ColumnarArray.toColumnarArray) 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)

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