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 });
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCopyPositionsWithCompactionsAndReorder.
@Test
public void testCopyPositionsWithCompactionsAndReorder() throws Exception {
Slice[] expectedValues = createExpectedValues(10);
DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
List<Integer> positionsToCopy = Ints.asList(50, 55, 40, 45, 60);
DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
assertEquals(copiedBlock.getDictionary().getPositionCount(), 2);
assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
assertBlock(copiedBlock.getDictionary(), new Slice[] { expectedValues[0], expectedValues[5] });
assertDictionaryIds(copiedBlock, 0, 1, 0, 1, 0);
}
use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.
the class TestDictionaryBlock method testCompact.
@Test
public void testCompact() throws Exception {
Slice[] expectedValues = createExpectedValues(5);
DictionaryBlock dictionaryBlock = createDictionaryBlockWithUnreferencedKeys(expectedValues, 10);
assertEquals(dictionaryBlock.isCompact(), false);
DictionaryBlock compactBlock = dictionaryBlock.compact();
assertNotEquals(dictionaryBlock.getDictionarySourceId(), compactBlock.getDictionarySourceId());
assertEquals(compactBlock.getDictionary().getPositionCount(), (expectedValues.length / 2) + 1);
assertBlock(compactBlock.getDictionary(), new Slice[] { expectedValues[0], expectedValues[1], expectedValues[3] });
assertDictionaryIds(compactBlock, 0, 1, 1, 2, 2, 0, 1, 1, 2, 2);
assertEquals(compactBlock.isCompact(), true);
DictionaryBlock reCompactedBlock = compactBlock.compact();
assertEquals(reCompactedBlock.getDictionarySourceId(), compactBlock.getDictionarySourceId());
}
Aggregations