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