use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testNonCachedLogicalBytes.
@Test
public void testNonCachedLogicalBytes() {
int numEntries = 10;
BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, numEntries);
// Over allocate dictionary indexes but only use the required limit.
int[] dictionaryIndexes = new int[numEntries + 10];
Arrays.fill(dictionaryIndexes, 1);
blockBuilder.appendNull();
dictionaryIndexes[0] = 0;
String string = "";
for (int i = 1; i < numEntries; i++) {
string += "a";
VARCHAR.writeSlice(blockBuilder, utf8Slice(string));
dictionaryIndexes[i] = numEntries - i;
}
// A dictionary block of size 10, 1st element -> null, 2nd element size -> 9....9th element size -> 1
// Pass different maxChunkSize and different offset and verify if it computes the chunk lengths correctly.
Block elementBlock = blockBuilder.build();
DictionaryBlock block = new DictionaryBlock(numEntries, elementBlock, dictionaryIndexes);
int elementSize = Integer.BYTES + Byte.BYTES;
long size = block.getRegionLogicalSizeInBytes(0, 1);
assertEquals(size, 0 + 1 * elementSize);
size = block.getRegionLogicalSizeInBytes(0, numEntries);
assertEquals(size, 45 + numEntries * elementSize);
size = block.getRegionLogicalSizeInBytes(1, 2);
assertEquals(size, 9 + 8 + 2 * elementSize);
size = block.getRegionLogicalSizeInBytes(9, 1);
assertEquals(size, 1 + 1 * elementSize);
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyRegionCreatesCompactBlock.
@Test
public void testCopyRegionCreatesCompactBlock() {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
DictionaryBlock copyRegionDictionaryBlock = (DictionaryBlock) dictionaryBlock.copyRegion(1, 3);
assertTrue(copyRegionDictionaryBlock.isCompact());
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsNoCompaction.
@Test
public void testCopyPositionsNoCompaction() {
Slice[] expectedValues = createExpectedValues(1);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
int[] positionsToCopy = new int[] { 0, 2, 4, 5 };
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, expectedValues);
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsSamePosition.
@Test
public void testCopyPositionsSamePosition() {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
int[] positionsToCopy = new int[] { 52, 52, 52 };
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[2] });
assertDictionaryIds(copiedBlock, 0, 0, 0);
}
use of com.facebook.presto.common.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsWithCompactionsAndReorder.
@Test
public void testCopyPositionsWithCompactionsAndReorder() {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
int[] positionsToCopy = new int[] { 50, 55, 40, 45, 60 };
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
assertEquals(copiedBlock.getDictionary().getPositionCount(), 2);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[0], expectedValues[5] });
assertDictionaryIds(copiedBlock, 0, 1, 0, 1, 0);
}
Aggregations