use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyRegionCreatesCompactBlock.
@Test
public void testCopyRegionCreatesCompactBlock() throws Exception {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
DictionaryBlock copyRegionDictionaryBlock = (DictionaryBlock) dictionaryBlock.copyRegion(1, 3);
assertTrue(copyRegionDictionaryBlock.isCompact());
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsSamePosition.
@Test
public void testCopyPositionsSamePosition() throws Exception {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
List<Integer> positionsToCopy = Ints.asList(52, 52, 52);
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
assertBlock(copiedBlock.getDictionary(), new Slice[] { expectedValues[2] });
assertDictionaryIds(copiedBlock, 0, 0, 0);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsNoCompaction.
@Test
public void testCopyPositionsNoCompaction() throws Exception {
Slice[] expectedValues = createExpectedValues(1);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
List<Integer> positionsToCopy = Ints.asList(0, 2, 4, 5);
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
assertBlock(copiedBlock.getDictionary(), expectedValues);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method createDictionaryBlockWithUnreferencedKeys.
private static DictionaryBlock createDictionaryBlockWithUnreferencedKeys(Slice[] expectedValues, int positionCount) {
// adds references to 0 and all odd indexes
int dictionarySize = expectedValues.length;
int[] ids = new int[positionCount];
for (int i = 0; i < positionCount; i++) {
int index = i % dictionarySize;
if (index % 2 == 0 && index != 0) {
index--;
}
ids[i] = index;
}
return new DictionaryBlock(positionCount, new SliceArrayBlock(dictionarySize, expectedValues), ids);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsWithCompaction.
@Test
public void testCopyPositionsWithCompaction() throws Exception {
Slice[] expectedValues = createExpectedValues(10);
Slice firstExpectedValue = expectedValues[0];
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
List<Integer> positionsToCopy = Ints.asList(0, 10, 20, 30, 40);
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
assertBlock(copiedBlock.getDictionary(), new Slice[] { firstExpectedValue });
assertBlock(copiedBlock, new Slice[] { firstExpectedValue, firstExpectedValue, firstExpectedValue, firstExpectedValue, firstExpectedValue });
}
Aggregations