Search in sources :

Example 11 with RunLengthEncodedBlock

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

the class TestRunLengthEncodedBlock method assertRleBlock.

private void assertRleBlock(int positionCount) {
    Slice expectedValue = createExpectedValue(0);
    Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
    Slice[] expectedValues = new Slice[positionCount];
    for (int position = 0; position < positionCount; position++) {
        expectedValues[position] = expectedValue;
    }
    assertBlock(block, TestRunLengthEncodedBlock::createBlockBuilder, expectedValues);
}
Also used : Slice(io.airlift.slice.Slice) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 12 with RunLengthEncodedBlock

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

the class TestRunLengthEncodedBlock method testEstimatedDataSizeForStats.

@Test
public void testEstimatedDataSizeForStats() {
    int positionCount = 10;
    Slice expectedValue = createExpectedValue(5);
    Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
    for (int postition = 0; postition < positionCount; postition++) {
        assertEquals(block.getEstimatedDataSizeForStats(postition), expectedValue.length());
    }
}
Also used : Slice(io.airlift.slice.Slice) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 13 with RunLengthEncodedBlock

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

the class ParquetFileWriter method appendRows.

@Override
public void appendRows(Page dataPage) {
    Block[] blocks = new Block[fileInputColumnIndexes.length];
    for (int i = 0; i < fileInputColumnIndexes.length; i++) {
        int inputColumnIndex = fileInputColumnIndexes[i];
        if (inputColumnIndex < 0) {
            blocks[i] = new RunLengthEncodedBlock(nullBlocks.get(i), dataPage.getPositionCount());
        } else {
            blocks[i] = dataPage.getBlock(inputColumnIndex);
        }
    }
    Page page = new Page(dataPage.getPositionCount(), blocks);
    try {
        parquetWriter.write(page);
    } catch (IOException | UncheckedIOException e) {
        throw new PrestoException(HIVE_WRITER_DATA_ERROR, e);
    }
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) UncheckedIOException(java.io.UncheckedIOException) PrestoException(com.facebook.presto.spi.PrestoException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 14 with RunLengthEncodedBlock

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

the class GroupIdOperator method generateNextPage.

private Page generateNextPage() {
    // generate 'n' pages for every input page, where n is the number of grouping sets
    Block[] outputBlocks = new Block[types.size()];
    for (int i = 0; i < groupingSetInputs[currentGroupingSet].length; i++) {
        if (groupingSetInputs[currentGroupingSet][i] == -1) {
            outputBlocks[i] = new RunLengthEncodedBlock(nullBlocks[i], currentPage.getPositionCount());
        } else {
            outputBlocks[i] = currentPage.getBlock(groupingSetInputs[currentGroupingSet][i]);
        }
    }
    outputBlocks[outputBlocks.length - 1] = new RunLengthEncodedBlock(groupIdBlocks[currentGroupingSet], currentPage.getPositionCount());
    currentGroupingSet = (currentGroupingSet + 1) % groupingSetInputs.length;
    Page outputPage = new Page(currentPage.getPositionCount(), outputBlocks);
    if (currentGroupingSet == 0) {
        currentPage = null;
    }
    return outputPage;
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 15 with RunLengthEncodedBlock

use of com.facebook.presto.common.block.RunLengthEncodedBlock 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)

Aggregations

RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)50 Block (com.facebook.presto.common.block.Block)27 Page (com.facebook.presto.common.Page)14 Test (org.testng.annotations.Test)9 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)7 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)6 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)6 PrestoException (com.facebook.presto.spi.PrestoException)6 ByteArrayBlock (com.facebook.presto.common.block.ByteArrayBlock)5 Slice (io.airlift.slice.Slice)5 IOException (java.io.IOException)4 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)3 LazyBlock (com.facebook.presto.common.block.LazyBlock)3 RowBlockBuilder (com.facebook.presto.common.block.RowBlockBuilder)3 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)2 BlockLease (com.facebook.presto.common.block.BlockLease)2 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)2 VariableWidthBlock (com.facebook.presto.common.block.VariableWidthBlock)2 Type (com.facebook.presto.common.type.Type)2 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)2