use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class BlockAssertions method createRLEBlock.
public static RunLengthEncodedBlock createRLEBlock(long value, int positionCount) {
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1);
BIGINT.writeLong(blockBuilder, value);
return new RunLengthEncodedBlock(blockBuilder.build(), positionCount);
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestRunLengthEncodedBlock method testPositionsSizeInBytes.
@Test
public void testPositionsSizeInBytes() {
Block valueBlock = createSingleValueBlock(createExpectedValue(10));
Block rleBlock = new RunLengthEncodedBlock(valueBlock, 10);
// Size in bytes is not fixed per position
assertTrue(rleBlock.fixedSizeInBytesPerPosition().isEmpty());
// Accepts specific position selection
boolean[] positions = new boolean[rleBlock.getPositionCount()];
positions[0] = true;
positions[1] = true;
assertEquals(rleBlock.getPositionsSizeInBytes(positions, 2), valueBlock.getSizeInBytes());
// Accepts null positions array with count only
assertEquals(rleBlock.getPositionsSizeInBytes(null, 2), valueBlock.getSizeInBytes());
// Always reports the same size in bytes regardless of positions
for (int positionCount = 0; positionCount < rleBlock.getPositionCount(); positionCount++) {
assertEquals(rleBlock.getPositionsSizeInBytes(null, positionCount), valueBlock.getSizeInBytes());
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestRunLengthEncodedBlock method testEstimatedDataSizeForStats.
@Test
public void testEstimatedDataSizeForStats() {
int positionCount = 10;
Slice expectedValue = createExpectedValue(5);
Block block = new RunLengthEncodedBlock(createSingleValueBlock(expectedValue), positionCount);
for (int postition = 0; postition < positionCount; postition++) {
assertEquals(block.getEstimatedDataSizeForStats(postition), expectedValue.length());
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class TestColumnarRow method assertRunLengthEncodedBlock.
private static <T> void assertRunLengthEncodedBlock(Block block, T[] expectedValues) {
for (int position = 0; position < block.getPositionCount(); position++) {
RunLengthEncodedBlock runLengthEncodedBlock = createTestRleBlock(block, position);
T[] expectedDictionaryValues = createTestRleExpectedValues(expectedValues, position);
assertBlock(runLengthEncodedBlock, expectedDictionaryValues);
assertColumnarRow(runLengthEncodedBlock, expectedDictionaryValues);
}
}
use of io.trino.spi.block.RunLengthEncodedBlock in project trino by trinodb.
the class AggregationTestUtils method maskPagesWithRle.
// Adds the mask as the last channel
private static Page[] maskPagesWithRle(boolean maskValue, Page... pages) {
Page[] maskedPages = new Page[pages.length];
for (int i = 0; i < pages.length; i++) {
Page page = pages[i];
maskedPages[i] = page.appendColumn(new RunLengthEncodedBlock(BooleanType.createBlockForSingleNonNullValue(maskValue), page.getPositionCount()));
}
return maskedPages;
}
Aggregations