use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
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 io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryBlock method testCompact.
@Test
public void testCompact() {
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(), TestDictionaryBlock::createBlockBuilder, 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());
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestColumnarArray method assertDictionaryBlock.
private static <T> void assertDictionaryBlock(Block block, T[] expectedValues) {
DictionaryBlock dictionaryBlock = createTestDictionaryBlock(block);
T[] expectedDictionaryValues = createTestDictionaryExpectedValues(expectedValues);
assertBlock(dictionaryBlock, expectedDictionaryValues);
assertColumnarArray(dictionaryBlock, expectedDictionaryValues);
assertRunLengthEncodedBlock(dictionaryBlock, expectedDictionaryValues);
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryAwarePageFilter method testDictionaryBlockProcessingWithUnusedFailure.
@Test
public void testDictionaryBlockProcessingWithUnusedFailure() {
// match some
testFilter(createDictionaryBlockWithUnusedEntries(20, 100), DictionaryBlock.class);
// match none
testFilter(createDictionaryBlockWithUnusedEntries(20, 0), DictionaryBlock.class);
// match all
testFilter(new DictionaryBlock(createLongsBlock(4, 5, -1), new int[100]), DictionaryBlock.class);
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
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