Search in sources :

Example 26 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project boostkit-bigdata by kunpengcompute.

the class BlockUtil method createIntegerDictionaryBlock.

public static Block createIntegerDictionaryBlock(int start, int length) {
    checkArgument(length > 5, "block must have more than 5 entries");
    int dictionarySize = length / 5;
    BlockBuilder builder = INTEGER.createBlockBuilder(null, dictionarySize);
    for (int i = start; i < start + dictionarySize; i++) {
        INTEGER.writeLong(builder, i);
    }
    int[] ids = new int[length];
    for (int i = 0; i < length; i++) {
        ids[i] = i % dictionarySize;
    }
    return new DictionaryBlock(builder.build(), ids);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 27 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryBlock method testEstimatedDataSizeForStats.

@Test
public void testEstimatedDataSizeForStats() {
    int positionCount = 10;
    int dictionaryPositionCount = 100;
    Slice[] expectedValues = createExpectedValues(positionCount);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, dictionaryPositionCount);
    for (int position = 0; position < dictionaryPositionCount; position++) {
        assertEquals(dictionaryBlock.getEstimatedDataSizeForStats(position), expectedValues[position % positionCount].length());
    }
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 28 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryBlock method testCompactAllKeysReferenced.

@Test
public void testCompactAllKeysReferenced() {
    Slice[] expectedValues = createExpectedValues(5);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 10);
    DictionaryBlock compactBlock = dictionaryBlock.compact();
    // When there is nothing to compact, we return the same block
    assertEquals(compactBlock.getDictionary(), dictionaryBlock.getDictionary());
    assertEquals(compactBlock.getPositionCount(), dictionaryBlock.getPositionCount());
    for (int position = 0; position < compactBlock.getPositionCount(); position++) {
        assertEquals(compactBlock.getId(position), dictionaryBlock.getId(position));
    }
    assertEquals(compactBlock.isCompact(), true);
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 29 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryAwarePageFilter method testDictionaryBlock.

@Test
public void testDictionaryBlock() {
    // match some
    testFilter(createDictionaryBlock(20, 100), LongArrayBlock.class);
    // match none
    testFilter(createDictionaryBlock(20, 0), LongArrayBlock.class);
    // match all
    testFilter(new DictionaryBlock(createLongSequenceBlock(4, 5), new int[100]), LongArrayBlock.class);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 30 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryAwarePageFilter method testDictionaryProcessingEnableDisable.

@Test
public void testDictionaryProcessingEnableDisable() {
    TestDictionaryFilter nestedFilter = new TestDictionaryFilter(true);
    DictionaryAwarePageFilter filter = new DictionaryAwarePageFilter(nestedFilter);
    DictionaryBlock ineffectiveBlock = createDictionaryBlock(100, 20);
    DictionaryBlock effectiveBlock = createDictionaryBlock(10, 100);
    // function will always processes the first dictionary
    nestedFilter.setExpectedType(LongArrayBlock.class);
    testFilter(filter, ineffectiveBlock, true);
    // last dictionary not effective, so dictionary processing is disabled
    nestedFilter.setExpectedType(DictionaryBlock.class);
    testFilter(filter, effectiveBlock, true);
    // last dictionary not effective, so dictionary processing is enabled again
    nestedFilter.setExpectedType(LongArrayBlock.class);
    testFilter(filter, ineffectiveBlock, true);
    // last dictionary not effective, so dictionary processing is disabled again
    nestedFilter.setExpectedType(DictionaryBlock.class);
    testFilter(filter, effectiveBlock, true);
}
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