Search in sources :

Example 46 with RunLengthEncodedBlock

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

the class DictionaryAwarePageFilter method filter.

@Override
public SelectedPositions filter(SqlFunctionProperties properties, Page page) {
    Block block = page.getBlock(0).getLoadedBlock();
    if (block instanceof RunLengthEncodedBlock) {
        Block value = ((RunLengthEncodedBlock) block).getValue();
        Optional<boolean[]> selectedPosition = processDictionary(properties, value);
        // in that case we fallback and process again so the correct error message sent
        if (selectedPosition.isPresent()) {
            return SelectedPositions.positionsRange(0, selectedPosition.get()[0] ? page.getPositionCount() : 0);
        }
    }
    if (block instanceof DictionaryBlock) {
        DictionaryBlock dictionaryBlock = (DictionaryBlock) block;
        // Attempt to process the dictionary.  If dictionary is processing has not been considered effective, an empty response will be returned
        Optional<boolean[]> selectedDictionaryPositions = processDictionary(properties, dictionaryBlock.getDictionary());
        // record the usage count regardless of dictionary processing choice, so we have stats for next time
        lastDictionaryUsageCount += page.getPositionCount();
        // if dictionary was processed, produce a dictionary block; otherwise do normal processing
        if (selectedDictionaryPositions.isPresent()) {
            return selectDictionaryPositions(dictionaryBlock, selectedDictionaryPositions.get());
        }
    }
    return filter.filter(properties, new Page(block));
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) 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 47 with RunLengthEncodedBlock

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

the class AbstractBlockEncodingBuffer method mapPositionsToNestedBlock.

/**
 * Map the positions for DictionaryBlock to its nested dictionaryBlock, and positions for RunLengthEncodedBlock
 * to its nested value block. For example, positions [0, 2, 5] on DictionaryBlock with dictionary block ['a', 'b', 'c']
 * and ids [1, 1, 2, 0, 2, 1] will be mapped to [1, 2, 1], and the copied data will be ['b', 'c', 'b'].
 */
protected DecodedBlockNode mapPositionsToNestedBlock(DecodedBlockNode decodedBlockNode) {
    Object decodedObject = decodedBlockNode.getDecodedBlock();
    if (decodedObject instanceof DictionaryBlock) {
        DictionaryBlock dictionaryBlock = (DictionaryBlock) decodedObject;
        mappedPositions = ensureCapacity(mappedPositions, positionCount, SMALL, NONE, bufferAllocator);
        for (int i = 0; i < positionCount; i++) {
            mappedPositions[i] = dictionaryBlock.getId(positions[i]);
        }
        positionsMapped = true;
        return decodedBlockNode.getChildren().get(0);
    }
    if (decodedObject instanceof RunLengthEncodedBlock) {
        mappedPositions = ensureCapacity(mappedPositions, positionCount, SMALL, INITIALIZE, bufferAllocator);
        positionsMapped = true;
        return decodedBlockNode.getChildren().get(0);
    }
    positionsMapped = false;
    return decodedBlockNode;
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 48 with RunLengthEncodedBlock

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

the class TestDictionaryAwarePageFilter method testRleBlockWithFailure.

@Test
public void testRleBlockWithFailure() {
    DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(true, LongArrayBlock.class);
    RunLengthEncodedBlock fail = new RunLengthEncodedBlock(createLongSequenceBlock(-10, -9), 100);
    assertThrows(NegativeValueException.class, () -> testFilter(filter, fail, true));
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 49 with RunLengthEncodedBlock

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

the class TestDictionaryAwarePageFilter method testRleBlock.

private static void testRleBlock(boolean filterRange) {
    DictionaryAwarePageFilter filter = createDictionaryAwarePageFilter(filterRange, LongArrayBlock.class);
    RunLengthEncodedBlock match = new RunLengthEncodedBlock(createLongSequenceBlock(4, 5), 100);
    testFilter(filter, match, filterRange);
    RunLengthEncodedBlock noMatch = new RunLengthEncodedBlock(createLongSequenceBlock(0, 1), 100);
    testFilter(filter, noMatch, filterRange);
}
Also used : RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

Example 50 with RunLengthEncodedBlock

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

the class RcFileReader method readBlock.

public Block readBlock(int columnIndex) throws IOException {
    checkArgument(readColumns.containsKey(columnIndex), "Column %s is not being read", columnIndex);
    checkState(currentChunkRowCount > 0, "No more data");
    if (columnIndex >= columns.length) {
        Type type = readColumns.get(columnIndex);
        Block nullBlock = type.createBlockBuilder(null, 1, 0).appendNull().build();
        return new RunLengthEncodedBlock(nullBlock, currentChunkRowCount);
    }
    return columns[columnIndex].readBlock(rowGroupPosition, currentChunkRowCount);
}
Also used : Type(com.facebook.presto.common.type.Type) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) Block(com.facebook.presto.common.block.Block) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock)

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