use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.
the class TestDictionaryBlock method testDictionarySizeMethods.
@Test
public void testDictionarySizeMethods() {
// fixed width block
Block fixedWidthBlock = new IntArrayBlock(100, Optional.empty(), IntStream.range(0, 100).toArray());
assertDictionarySizeMethods(fixedWidthBlock);
// variable width block
Block variableWidthBlock = createSlicesBlock(createExpectedValues(fixedWidthBlock.getPositionCount()));
assertDictionarySizeMethods(variableWidthBlock);
// sparse dictionary block from getPositions
assertDictionarySizeMethods(fixedWidthBlock.getPositions(IntStream.range(0, 50).toArray(), 0, 50));
assertDictionarySizeMethods(variableWidthBlock.getPositions(IntStream.range(0, 50).toArray(), 0, 50));
// nested sparse dictionary block via constructor
assertDictionarySizeMethods(new DictionaryBlock(fixedWidthBlock, IntStream.range(0, 50).toArray()));
assertDictionarySizeMethods(new DictionaryBlock(variableWidthBlock, IntStream.range(0, 50).toArray()));
// compact dictionary block via getPositions
int[] positions = createCompactRepeatingIdsRange(fixedWidthBlock.getPositionCount());
assertDictionarySizeMethods(fixedWidthBlock.getPositions(positions, 0, positions.length));
assertDictionarySizeMethods(variableWidthBlock.getPositions(positions, 0, positions.length));
// nested compact dictionary block via constructor
assertDictionarySizeMethods(new DictionaryBlock(fixedWidthBlock, createCompactRepeatingIdsRange(fixedWidthBlock.getPositionCount())));
assertDictionarySizeMethods(new DictionaryBlock(variableWidthBlock, createCompactRepeatingIdsRange(variableWidthBlock.getPositionCount())));
}
use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.
the class TestDictionaryBlock method testBasicGetPositions.
@Test
public void testBasicGetPositions() {
Slice[] expectedValues = createExpectedValues(10);
Block dictionaryBlock = new DictionaryBlock(createSlicesBlock(expectedValues), new int[] { 0, 1, 2, 3, 4, 5 });
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[0], expectedValues[1], expectedValues[2], expectedValues[3], expectedValues[4], expectedValues[5] });
DictionaryId dictionaryId = ((DictionaryBlock) dictionaryBlock).getDictionarySourceId();
// first getPositions
dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 8, 1, 2, 4, 5, 7, 9 }, 2, 4);
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[4], expectedValues[5] });
assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
// second getPositions
dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 1, 3, 0, 0 }, 0, 3);
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
// third getPositions; we do not validate if -1 is an invalid position
dictionaryBlock = dictionaryBlock.getPositions(new int[] { -1, -1, 0, 1, 2 }, 2, 3);
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
// mixed getPositions
dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 2, 2 }, 0, 3);
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[5], expectedValues[5] });
assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
// duplicated getPositions
dictionaryBlock = dictionaryBlock.getPositions(new int[] { 1, 1, 1, 1, 1 }, 0, 5);
assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5] });
assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
// out of range
for (int position : ImmutableList.of(-1, 6)) {
try {
dictionaryBlock.getPositions(new int[] { position }, 0, 1);
fail("Expected to fail");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Invalid position"));
}
}
for (int offset : ImmutableList.of(-1, 6)) {
try {
dictionaryBlock.getPositions(new int[] { 0 }, offset, 1);
fail("Expected to fail");
} catch (IndexOutOfBoundsException e) {
assertTrue(e.getMessage().startsWith("Invalid offset"));
}
}
for (int length : ImmutableList.of(-1, 6)) {
try {
dictionaryBlock.getPositions(new int[] { 0 }, 0, length);
fail("Expected to fail");
} catch (IndexOutOfBoundsException e) {
assertTrue(e.getMessage().startsWith("Invalid offset"));
}
}
}
use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.
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);
}
use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.
the class TestBlockEncodingBuffers method buildDictionaryBlockStatus.
private BlockStatus buildDictionaryBlockStatus(BlockStatus dictionary, int positionCount) {
DictionaryBlock dictionaryBlock = createRandomDictionaryBlock(dictionary.block, positionCount);
int[] mappedExpectedRowSizes = IntStream.range(0, positionCount).map(i -> dictionary.expectedRowSizes[dictionaryBlock.getId(i)]).toArray();
return new BlockStatus(dictionaryBlock, mappedExpectedRowSizes);
}
use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.
the class TestDictionaryAwarePageFilter method createDictionaryBlock.
private static DictionaryBlock createDictionaryBlock(int dictionarySize, int blockSize) {
Block dictionary = createLongSequenceBlock(0, dictionarySize);
int[] ids = new int[blockSize];
Arrays.setAll(ids, index -> index % dictionarySize);
return new DictionaryBlock(dictionary, ids);
}
Aggregations