use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class MultiChannelGroupByHash method addDictionaryPage.
private void addDictionaryPage(Page page) {
verify(canProcessDictionary(page), "invalid call to addDictionaryPage");
DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]);
updateDictionaryLookBack(dictionaryBlock.getDictionary());
Page dictionaryPage = createPageWithExtractedDictionary(page);
for (int i = 0; i < page.getPositionCount(); i++) {
int positionInDictionary = dictionaryBlock.getId(i);
getGroupId(hashGenerator, dictionaryPage, positionInDictionary);
}
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class BlockAssertions method createLongDictionaryBlock.
public static Block createLongDictionaryBlock(int start, int length) {
checkArgument(length > 5, "block must have more than 5 entries");
int dictionarySize = length / 5;
BlockBuilder builder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), dictionarySize);
for (int i = start; i < start + dictionarySize; i++) {
BIGINT.writeLong(builder, i);
}
int[] ids = new int[length];
for (int i = 0; i < length; i++) {
ids[i] = i % dictionarySize;
}
return new DictionaryBlock(length, builder.build(), ids);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testSizeInBytes.
@Test
public void testSizeInBytes() throws Exception {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
assertEquals(dictionaryBlock.getSizeInBytes(), dictionaryBlock.getDictionary().getSizeInBytes() + (100 * SIZE_OF_INT));
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCompactAllKeysReferenced.
@Test
public void testCompactAllKeysReferenced() throws Exception {
Slice[] expectedValues = createExpectedValues(5);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 10);
DictionaryBlock compactBlock = dictionaryBlock.compact();
// When there is nothing to compact, we return the same block
assertEquals(compactBlock.getDictionary(), dictionaryBlock.getDictionary());
assertEquals(compactBlock.getPositionCount(), dictionaryBlock.getPositionCount());
for (int position = 0; position < compactBlock.getPositionCount(); position++) {
assertEquals(compactBlock.getId(position), dictionaryBlock.getId(position));
}
assertEquals(compactBlock.isCompact(), true);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method createDictionaryBlock.
private static DictionaryBlock createDictionaryBlock(Slice[] expectedValues, int positionCount) {
int dictionarySize = expectedValues.length;
int[] ids = new int[positionCount];
for (int i = 0; i < positionCount; i++) {
ids[i] = i % dictionarySize;
}
return new DictionaryBlock(positionCount, new SliceArrayBlock(dictionarySize, expectedValues), ids);
}
Aggregations