use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryAwarePageFilter method createDictionaryBlockWithFailure.
private static DictionaryBlock createDictionaryBlockWithFailure(int dictionarySize, int blockSize) {
Block dictionary = createLongSequenceBlock(-10, dictionarySize - 10);
int[] ids = new int[blockSize];
Arrays.setAll(ids, index -> index % dictionarySize);
return new DictionaryBlock(dictionary, ids);
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryAwarePageProjection method testDictionaryProcessingEnableDisable.
@Test(dataProvider = "forceYield")
public void testDictionaryProcessingEnableDisable(boolean forceYield) {
DictionaryAwarePageProjection projection = createProjection();
// function will always processes the first dictionary
DictionaryBlock ineffectiveBlock = createDictionaryBlock(100, 20);
testProjectRange(ineffectiveBlock, DictionaryBlock.class, projection, forceYield);
testProjectFastReturnIgnoreYield(ineffectiveBlock, projection);
// dictionary processing can reuse the last dictionary
// in this case, we don't even check yield signal; make yieldForce to false
testProjectList(ineffectiveBlock, DictionaryBlock.class, projection, false);
// last dictionary not effective, so dictionary processing is disabled
DictionaryBlock effectiveBlock = createDictionaryBlock(10, 100);
testProjectRange(effectiveBlock, LongArrayBlock.class, projection, forceYield);
testProjectList(effectiveBlock, LongArrayBlock.class, projection, forceYield);
// last dictionary effective, so dictionary processing is enabled again
testProjectRange(ineffectiveBlock, DictionaryBlock.class, projection, forceYield);
testProjectFastReturnIgnoreYield(ineffectiveBlock, projection);
// dictionary processing can reuse the last dictionary
// in this case, we don't even check yield signal; make yieldForce to false
testProjectList(ineffectiveBlock, DictionaryBlock.class, projection, false);
// last dictionary not effective, so dictionary processing is disabled again
testProjectRange(effectiveBlock, LongArrayBlock.class, projection, forceYield);
testProjectList(effectiveBlock, LongArrayBlock.class, projection, forceYield);
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryAwarePageProjection method testDictionaryBlock.
@Test(dataProvider = "forceYield")
public void testDictionaryBlock(boolean forceYield) {
DictionaryBlock block = createDictionaryBlock(10, 100);
testProject(block, DictionaryBlock.class, forceYield);
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class ArrayCombinationsFunction method combinations.
@TypeParameter("T")
@SqlType("array(array(T))")
public static Block combinations(@TypeParameter("T") Type elementType, @SqlType("array(T)") Block array, @SqlType(INTEGER) long n) {
int arrayLength = array.getPositionCount();
int combinationLength = toIntExact(n);
checkCondition(combinationLength >= 0, INVALID_FUNCTION_ARGUMENT, "combination size must not be negative: %s", combinationLength);
checkCondition(combinationLength <= MAX_COMBINATION_LENGTH, INVALID_FUNCTION_ARGUMENT, "combination size must not exceed %s: %s", MAX_COMBINATION_LENGTH, combinationLength);
ArrayType arrayType = new ArrayType(elementType);
if (combinationLength > arrayLength) {
return arrayType.createBlockBuilder(new PageBuilderStatus().createBlockBuilderStatus(), 0).build();
}
int combinationCount = combinationCount(arrayLength, combinationLength);
checkCondition(combinationCount * (long) combinationLength <= MAX_RESULT_ELEMENTS, INVALID_FUNCTION_ARGUMENT, "combinations exceed max size");
int[] ids = new int[combinationCount * combinationLength];
int idsPosition = 0;
int[] combination = firstCombination(arrayLength, combinationLength);
do {
arraycopy(combination, 0, ids, idsPosition, combinationLength);
idsPosition += combinationLength;
} while (nextCombination(combination, combinationLength));
verify(idsPosition == ids.length, "idsPosition != ids.length, %s and %s respectively", idsPosition, ids.length);
int[] offsets = new int[combinationCount + 1];
setAll(offsets, i -> i * combinationLength);
return ArrayBlock.fromElementBlock(combinationCount, Optional.empty(), offsets, new DictionaryBlock(array, ids));
}
use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.
the class TestDictionaryBlock method testCompactGetPositions.
@Test
public void testCompactGetPositions() {
DictionaryBlock block = new DictionaryBlock(createSlicesBlock(createExpectedValues(10)), new int[] { 0, 1, 2, 3, 4, 5 }).compact();
// 3, 3, 4, 5, 2, 0, 1, 1
block = (DictionaryBlock) block.getPositions(new int[] { 3, 3, 4, 5, 2, 0, 1, 1 }, 0, 7);
assertTrue(block.isCompact());
// 3, 3, 4, 5, 2, 0, 1, 1, 0, 2, 5, 4, 3
block = (DictionaryBlock) block.getPositions(new int[] { 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1 }, 0, 12);
assertTrue(block.isCompact());
// 3, 4, 3, 4, 3
block = (DictionaryBlock) block.getPositions(new int[] { 0, 2, 0, 2, 0 }, 0, 5);
assertFalse(block.isCompact());
block = block.compact();
// 3, 4, 4, 4
block = (DictionaryBlock) block.getPositions(new int[] { 0, 1, 1, 1 }, 0, 4);
assertTrue(block.isCompact());
// 4, 4, 4, 4
block = (DictionaryBlock) block.getPositions(new int[] { 1, 1, 1, 1 }, 0, 4);
assertFalse(block.isCompact());
block = block.compact();
// 4
block = (DictionaryBlock) block.getPositions(new int[] { 0 }, 0, 1);
assertTrue(block.isCompact());
// empty
block = (DictionaryBlock) block.getPositions(new int[] {}, 0, 0);
assertFalse(block.isCompact());
block = block.compact();
// empty
block = (DictionaryBlock) block.getPositions(new int[] {}, 0, 0);
assertTrue(block.isCompact());
}
Aggregations