use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestPageProcessorCompiler method testSanityRLE.
@Test
public void testSanityRLE() {
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(field(0, BIGINT), field(1, VARCHAR)), MAX_BATCH_SIZE).get();
Slice varcharValue = Slices.utf8Slice("hello");
Page page = new Page(RunLengthEncodedBlock.create(BIGINT, 123L, 100), RunLengthEncodedBlock.create(VARCHAR, varcharValue, 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
assertTrue(outputPage.getBlock(1) instanceof RunLengthEncodedBlock);
RunLengthEncodedBlock rleBlock = (RunLengthEncodedBlock) outputPage.getBlock(0);
assertEquals(BIGINT.getLong(rleBlock.getValue(), 0), 123L);
RunLengthEncodedBlock rleBlock1 = (RunLengthEncodedBlock) outputPage.getBlock(1);
assertEquals(VARCHAR.getSlice(rleBlock1.getValue(), 0), varcharValue);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class UnionColumnReader method getBlocks.
private Block[] getBlocks(int positionCount) throws IOException {
if (dataStream == null) {
throw new OrcCorruptionException(column.getOrcDataSourceId(), "Value is not null but data stream is missing");
}
Block[] blocks = new Block[fieldReaders.size() + 1];
byte[] tags = dataStream.next(positionCount);
blocks[0] = new ByteArrayBlock(positionCount, Optional.empty(), tags);
boolean[][] valueIsNonNull = new boolean[fieldReaders.size()][positionCount];
int[] nonNullValueCount = new int[fieldReaders.size()];
for (int i = 0; i < positionCount; i++) {
valueIsNonNull[tags[i]][i] = true;
nonNullValueCount[tags[i]]++;
}
for (int i = 0; i < fieldReaders.size(); i++) {
Type fieldType = type.getTypeParameters().get(i + 1);
if (nonNullValueCount[i] > 0) {
ColumnReader reader = fieldReaders.get(i);
reader.prepareNextRead(nonNullValueCount[i]);
Block rawBlock = blockFactory.createBlock(nonNullValueCount[i], reader::readBlock, true);
blocks[i + 1] = new LazyBlock(positionCount, new UnpackLazyBlockLoader(rawBlock, fieldType, valueIsNonNull[i]));
} else {
blocks[i + 1] = new RunLengthEncodedBlock(fieldType.createBlockBuilder(null, 1).appendNull().build(), positionCount);
}
}
return blocks;
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class BigintGroupByHash method addPage.
@Override
public Work<?> addPage(Page page) {
currentPageSizeInBytes = page.getRetainedSizeInBytes();
Block block = page.getBlock(hashChannel);
if (block instanceof RunLengthEncodedBlock) {
return new AddRunLengthEncodedPageWork((RunLengthEncodedBlock) block);
}
if (block instanceof DictionaryBlock) {
return new AddDictionaryPageWork((DictionaryBlock) block);
}
return new AddPageWork(block);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class BigintGroupByHash method getGroupIds.
@Override
public Work<GroupByIdBlock> getGroupIds(Page page) {
currentPageSizeInBytes = page.getRetainedSizeInBytes();
Block block = page.getBlock(hashChannel);
if (block instanceof RunLengthEncodedBlock) {
return new GetRunLengthEncodedGroupIdsWork((RunLengthEncodedBlock) block);
}
if (block instanceof DictionaryBlock) {
return new GetDictionaryGroupIdsWork((DictionaryBlock) block);
}
return new GetGroupIdsWork(page.getBlock(hashChannel));
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class GroupIdOperator method generateNextPage.
private Page generateNextPage() {
// generate 'n' pages for every input page, where n is the number of grouping sets
Block[] outputBlocks = new Block[types.size()];
for (int i = 0; i < groupingSetInputs[currentGroupingSet].length; i++) {
if (groupingSetInputs[currentGroupingSet][i] == -1) {
outputBlocks[i] = new RunLengthEncodedBlock(nullBlocks[i], currentPage.getPositionCount());
} else {
outputBlocks[i] = currentPage.getBlock(groupingSetInputs[currentGroupingSet][i]);
}
}
outputBlocks[outputBlocks.length - 1] = new RunLengthEncodedBlock(groupIdBlocks[currentGroupingSet], currentPage.getPositionCount());
currentGroupingSet = (currentGroupingSet + 1) % groupingSetInputs.length;
Page outputPage = new Page(currentPage.getPositionCount(), outputBlocks);
if (currentGroupingSet == 0) {
currentPage = null;
}
return outputPage;
}
Aggregations