Search in sources :

Example 1 with RunLengthEncodedBlock

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

the class GenericPageProcessor method filterPage.

private int[] filterPage(Page page) {
    int[] selected = new int[page.getPositionCount()];
    int index = 0;
    if (filterFunction.getInputChannels().size() == 1) {
        int channel = getOnlyElement(filterFunction.getInputChannels());
        if (page.getBlock(channel) instanceof DictionaryBlock) {
            DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channel);
            Block dictionary = dictionaryBlock.getDictionary();
            Block[] blocks = new Block[page.getPositionCount()];
            blocks[channel] = dictionary;
            boolean[] selectedDictionaryPositions;
            if (inputFilterDictionary == dictionary) {
                selectedDictionaryPositions = filterResult;
            } else {
                selectedDictionaryPositions = new boolean[dictionary.getPositionCount()];
                for (int i = 0; i < dictionary.getPositionCount(); i++) {
                    selectedDictionaryPositions[i] = filterFunction.filter(i, blocks);
                }
                inputFilterDictionary = dictionary;
                filterResult = selectedDictionaryPositions;
            }
            for (int i = 0; i < page.getPositionCount(); i++) {
                if (selectedDictionaryPositions[dictionaryBlock.getId(i)]) {
                    selected[index] = i;
                    index++;
                }
            }
            return copyOf(selected, index);
        }
        if (page.getBlock(channel) instanceof RunLengthEncodedBlock) {
            RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) page.getBlock(channel);
            Block[] blocks = new Block[page.getPositionCount()];
            blocks[channel] = rleBlock.getValue();
            if (filterFunction.filter(0, blocks)) {
                return IntStream.range(0, page.getPositionCount()).toArray();
            }
            return new int[0];
        }
    }
    Block[] blocks = page.getBlocks();
    for (int position = 0; position < page.getPositionCount(); position++) {
        if (filterFunction.filter(position, blocks)) {
            selected[index] = position;
            index++;
        }
    }
    return copyOf(selected, index);
}
Also used : DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock)

Example 2 with RunLengthEncodedBlock

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

the class AbstractTestAggregationFunction method testAllPositionsNull.

@Test
public void testAllPositionsNull() throws Exception {
    // if there are no parameters skip this test
    List<Type> parameterTypes = getFunction().getParameterTypes();
    if (parameterTypes.isEmpty()) {
        return;
    }
    Block[] blocks = new Block[parameterTypes.size()];
    for (int i = 0; i < parameterTypes.size(); i++) {
        Block nullValueBlock = parameterTypes.get(0).createBlockBuilder(new BlockBuilderStatus(), 1).appendNull().build();
        blocks[i] = new RunLengthEncodedBlock(nullValueBlock, 10);
    }
    testAggregation(getExpectedValueIncludingNulls(0, 0, 10), blocks);
}
Also used : Type(com.facebook.presto.spi.type.Type) Block(com.facebook.presto.spi.block.Block) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Example 3 with RunLengthEncodedBlock

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

the class GenericPageProcessor method projectColumnarDictionary.

private Block projectColumnarDictionary(Page inputPage, int[] selectedPositions, ProjectionFunction projection, Map<DictionaryId, DictionaryId> dictionarySourceIds) {
    int inputChannel = getOnlyElement(projection.getInputChannels());
    Block[] blocks = new Block[inputPage.getChannelCount()];
    if (inputPage.getBlock(inputChannel) instanceof RunLengthEncodedBlock) {
        RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) inputPage.getBlock(inputChannel);
        BlockBuilder builder = projection.getType().createBlockBuilder(new BlockBuilderStatus(), 1);
        blocks[inputChannel] = rleBlock.getValue();
        projection.project(0, blocks, builder);
        return new RunLengthEncodedBlock(builder.build(), selectedPositions.length);
    }
    Block outputDictionary = projectDictionary(projection, inputPage);
    int[] outputIds = filterIds(projection, inputPage, selectedPositions);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) inputPage.getBlock(inputChannel);
    DictionaryId sourceId = dictionarySourceIds.get(dictionaryBlock.getDictionarySourceId());
    if (sourceId == null) {
        sourceId = randomDictionaryId();
        dictionarySourceIds.put(dictionaryBlock.getDictionarySourceId(), sourceId);
    }
    return new DictionaryBlock(selectedPositions.length, outputDictionary, outputIds, false, sourceId);
}
Also used : DictionaryId.randomDictionaryId(com.facebook.presto.spi.block.DictionaryId.randomDictionaryId) DictionaryId(com.facebook.presto.spi.block.DictionaryId) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus)

Example 4 with RunLengthEncodedBlock

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

the class GenericPageProcessor method canDictionaryProcess.

private static boolean canDictionaryProcess(ProjectionFunction projection, Page inputPage) {
    if (!projection.isDeterministic()) {
        return false;
    }
    Set<Integer> inputChannels = projection.getInputChannels();
    if (inputChannels.size() != 1) {
        return false;
    }
    Block block = inputPage.getBlock(getOnlyElement(inputChannels));
    return block instanceof DictionaryBlock || block instanceof RunLengthEncodedBlock;
}
Also used : DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Block(com.facebook.presto.spi.block.Block) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) LazyBlock(com.facebook.presto.spi.block.LazyBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock) RunLengthEncodedBlock(com.facebook.presto.spi.block.RunLengthEncodedBlock)

Aggregations

Block (com.facebook.presto.spi.block.Block)4 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)4 DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)3 LazyBlock (com.facebook.presto.spi.block.LazyBlock)3 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)2 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)1 DictionaryId (com.facebook.presto.spi.block.DictionaryId)1 DictionaryId.randomDictionaryId (com.facebook.presto.spi.block.DictionaryId.randomDictionaryId)1 Type (com.facebook.presto.spi.type.Type)1 Test (org.testng.annotations.Test)1