use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class BenchmarkGroupByHash method createBigintPages.
private static List<Page> createBigintPages(int positionCount, int groupCount, int channelCount, boolean hashEnabled, boolean useMixedBlockTypes) {
List<Type> types = Collections.nCopies(channelCount, BIGINT);
ImmutableList.Builder<Page> pages = ImmutableList.builder();
if (hashEnabled) {
types = ImmutableList.copyOf(Iterables.concat(types, ImmutableList.of(BIGINT)));
}
PageBuilder pageBuilder = new PageBuilder(types);
int pageCount = 0;
for (int position = 0; position < positionCount; position++) {
int rand = ThreadLocalRandom.current().nextInt(groupCount);
pageBuilder.declarePosition();
for (int numChannel = 0; numChannel < channelCount; numChannel++) {
BIGINT.writeLong(pageBuilder.getBlockBuilder(numChannel), rand);
}
if (hashEnabled) {
BIGINT.writeLong(pageBuilder.getBlockBuilder(channelCount), AbstractLongType.hash(rand));
}
if (pageBuilder.isFull()) {
Page page = pageBuilder.build();
pageBuilder.reset();
if (useMixedBlockTypes) {
if (pageCount % 3 == 0) {
pages.add(page);
} else if (pageCount % 3 == 1) {
// rle page
Block[] blocks = new Block[page.getChannelCount()];
for (int channel = 0; channel < blocks.length; ++channel) {
blocks[channel] = new RunLengthEncodedBlock(page.getBlock(channel).getSingleValueBlock(0), page.getPositionCount());
}
pages.add(new Page(blocks));
} else {
// dictionary page
int[] positions = IntStream.range(0, page.getPositionCount()).toArray();
Block[] blocks = new Block[page.getChannelCount()];
for (int channel = 0; channel < page.getChannelCount(); ++channel) {
blocks[channel] = new DictionaryBlock(page.getBlock(channel), positions);
}
pages.add(new Page(blocks));
}
} else {
pages.add(page);
}
pageCount++;
}
}
pages.add(pageBuilder.build());
return pages.build();
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class RcFileFileWriter 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 {
rcFileWriter.write(page);
} catch (IOException | UncheckedIOException e) {
throw new TrinoException(HIVE_WRITER_DATA_ERROR, e);
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class DictionaryAwarePageFilter method filter.
@Override
public SelectedPositions filter(ConnectorSession session, Page page) {
Block block = page.getBlock(0).getLoadedBlock();
if (block instanceof RunLengthEncodedBlock) {
Block value = ((RunLengthEncodedBlock) block).getValue();
Optional<boolean[]> selectedPosition = processDictionary(session, 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(session, 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(session, new Page(block));
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
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);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
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);
}
Aggregations