use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestGroupByHash method testRunLengthEncodedBigintGroupByHash.
@Test
public void testRunLengthEncodedBigintGroupByHash() {
GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
Block block = BlockAssertions.createLongsBlock(0L);
Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
Page page = new Page(new RunLengthEncodedBlock(block, 2), new RunLengthEncodedBlock(hashBlock, 2));
groupByHash.addPage(page).process();
assertEquals(groupByHash.getGroupCount(), 1);
Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
work.process();
GroupByIdBlock groupIds = work.getResult();
assertEquals(groupIds.getGroupCount(), 1);
assertEquals(groupIds.getPositionCount(), 2);
assertEquals(groupIds.getGroupId(0), 0);
assertEquals(groupIds.getGroupId(1), 0);
List<Block> children = groupIds.getChildren();
assertEquals(children.size(), 1);
assertTrue(children.get(0) instanceof RunLengthEncodedBlock);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestPageProcessorCompiler method testSanityFilterOnRLE.
@Test
public void testSanityFilterOnRLE() {
ResolvedFunction lessThan = functionResolution.resolveOperator(LESS_THAN, ImmutableList.of(BIGINT, BIGINT));
CallExpression filter = new CallExpression(lessThan, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)));
PageProcessor processor = compiler.compilePageProcessor(Optional.of(filter), ImmutableList.of(field(0, BIGINT)), MAX_BATCH_SIZE).get();
Page page = new Page(createRLEBlock(5L, 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);
RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestOrcDeletedRows method createTestPage.
private Page createTestPage(int originalTransactionStart, int originalTransactionEnd) {
int size = originalTransactionEnd - originalTransactionStart;
BlockBuilder originalTransaction = BIGINT.createFixedSizeBlockBuilder(size);
for (long i = originalTransactionStart; i < originalTransactionEnd; i++) {
originalTransaction.writeLong(i);
}
return new Page(size, originalTransaction.build(), new RunLengthEncodedBlock(bucketBlock, size), new RunLengthEncodedBlock(rowIdBlock, size));
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestPageSplitterUtil method testSplitPageNonDecreasingPageSize.
@Test
public void testSplitPageNonDecreasingPageSize() {
int positionCount = 100;
int maxPageSizeInBytes = 1;
List<Type> types = ImmutableList.of(VARCHAR);
Slice expectedValue = wrappedBuffer("test".getBytes(UTF_8));
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, 1, expectedValue.length());
blockBuilder.writeBytes(expectedValue, 0, expectedValue.length()).closeEntry();
Block rleBlock = new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
Page initialPage = new Page(rleBlock);
List<Page> pages = splitPage(initialPage, maxPageSizeInBytes);
// the page should only be split in half as the recursion should terminate
// after seeing that the size of the Page doesn't decrease
assertEquals(pages.size(), 2);
Page first = pages.get(0);
Page second = pages.get(1);
// the size of the pages will remain the same and should be greater than the maxPageSizeInBytes
assertGreaterThan((int) first.getSizeInBytes(), maxPageSizeInBytes);
assertGreaterThan((int) second.getSizeInBytes(), maxPageSizeInBytes);
assertPositionCount(pages, positionCount);
MaterializedResult actual = toMaterializedResult(TEST_SESSION, types, pages);
MaterializedResult expected = toMaterializedResult(TEST_SESSION, types, ImmutableList.of(initialPage));
assertEquals(actual, expected);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
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