Search in sources :

Example 11 with DictionaryBlock

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);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) LazyBlock(io.prestosql.spi.block.LazyBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Example 12 with DictionaryBlock

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);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 13 with DictionaryBlock

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);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 14 with DictionaryBlock

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));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) PageBuilderStatus(io.prestosql.spi.block.PageBuilderStatus) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) TypeParameter(io.prestosql.spi.function.TypeParameter) SqlType(io.prestosql.spi.function.SqlType)

Example 15 with DictionaryBlock

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());
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Aggregations

DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)69 Block (io.prestosql.spi.block.Block)31 Test (org.testng.annotations.Test)29 Slice (io.airlift.slice.Slice)17 BlockBuilder (io.prestosql.spi.block.BlockBuilder)16 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)11 Page (io.prestosql.spi.Page)9 ColumnarTestUtils.assertBlock (io.prestosql.block.ColumnarTestUtils.assertBlock)8 LazyBlock (io.prestosql.spi.block.LazyBlock)8 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)8 PageBuilderStatus (io.prestosql.spi.block.PageBuilderStatus)8 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)7 DictionaryId (io.prestosql.spi.block.DictionaryId)6 TestUnnesterUtil.createSimpleBlock (io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock)5 DictionaryId.randomDictionaryId (io.prestosql.spi.block.DictionaryId.randomDictionaryId)5 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)4 BlockAssertions.createLongDictionaryBlock (io.prestosql.block.BlockAssertions.createLongDictionaryBlock)3 ColumnarTestUtils.createTestDictionaryBlock (io.prestosql.block.ColumnarTestUtils.createTestDictionaryBlock)3 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)3 JoinProbeFactory (io.prestosql.operator.JoinProbe.JoinProbeFactory)3