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);
}
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);
}
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);
}
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;
}
Aggregations