use of io.trino.spi.block.DictionaryBlock in project trino by trinodb.
the class TestUnnestBlockBuilder method testAppendRange.
private static void testAppendRange(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
assertTrue(values.length >= 3, "test requires at least 3 elements in values");
int startIndex = 1;
int length = values.length - 2;
unnestBlockBuilder.appendRange(startIndex, length);
Block block = unnestBlockBuilder.buildOutputAndFlush();
assertTrue(block instanceof DictionaryBlock);
assertBlock(block, Arrays.copyOfRange(values, startIndex, startIndex + length));
}
use of io.trino.spi.block.DictionaryBlock in project trino by trinodb.
the class TestUnnestBlockBuilder method testAppendSingleElement.
private static void testAppendSingleElement(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
// Test unnestBlockBuilder output over the course of building output
for (int testCount = 1; testCount <= values.length; testCount++) {
unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
for (int i = 0; i < testCount; i++) {
unnestBlockBuilder.appendElement(i);
}
Block block = unnestBlockBuilder.buildOutputAndFlush();
assertTrue(block instanceof DictionaryBlock);
assertBlock(block, Arrays.copyOf(values, testCount));
}
}
use of io.trino.spi.block.DictionaryBlock in project trino by trinodb.
the class TestUnnestBlockBuilder method testAppendNull.
private static void testAppendNull(UnnestBlockBuilder unnestBlockBuilder, Slice[] values) {
assertTrue(values.length >= 1, "values should have at least one element");
int nullIndex = -1;
for (int i = 0; i < values.length; i++) {
if (values[i] == null) {
nullIndex = i;
break;
}
}
// Test-1: appending a non-null element
unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
unnestBlockBuilder.appendElement(0);
Block block = unnestBlockBuilder.buildOutputAndFlush();
assertTrue(block instanceof DictionaryBlock);
assertBlock(block, new Slice[] { values[0] });
// Test-2: appending a non-null element and a null.
unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
unnestBlockBuilder.appendElement(0);
unnestBlockBuilder.appendNull();
block = unnestBlockBuilder.buildOutputAndFlush();
assertTrue((block instanceof DictionaryBlock) || (nullIndex == -1));
assertFalse((block instanceof DictionaryBlock) && (nullIndex == -1));
assertBlock(block, new Slice[] { values[0], null });
// Test-3: appending a non-null element, a null, and another non-null element.
unnestBlockBuilder.startNewOutput(new PageBuilderStatus(), 10);
unnestBlockBuilder.appendElement(0);
unnestBlockBuilder.appendNull();
unnestBlockBuilder.appendElement(0);
block = unnestBlockBuilder.buildOutputAndFlush();
assertTrue((block instanceof DictionaryBlock) || (nullIndex == -1));
assertFalse((block instanceof DictionaryBlock) && (nullIndex == -1));
assertBlock(block, new Slice[] { values[0], null, values[0] });
}
use of io.trino.spi.block.DictionaryBlock 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.DictionaryBlock 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));
}
Aggregations