Search in sources :

Example 6 with DictionaryId

use of com.facebook.presto.common.block.DictionaryId in project presto by prestodb.

the class TestPage method testCompactDictionaryBlocks.

@Test
public void testCompactDictionaryBlocks() {
    int positionCount = 100;
    // Create 2 dictionary blocks with the same source id
    DictionaryId commonSourceId = randomDictionaryId();
    int commonDictionaryUsedPositions = 20;
    int[] commonDictionaryIds = getDictionaryIds(positionCount, commonDictionaryUsedPositions);
    // first dictionary contains "varbinary" values
    Slice[] dictionaryValues1 = createExpectedValues(50);
    Block dictionary1 = createSlicesBlock(dictionaryValues1);
    DictionaryBlock commonSourceIdBlock1 = new DictionaryBlock(positionCount, dictionary1, commonDictionaryIds, commonSourceId);
    // second dictionary block is "length(firstColumn)"
    BlockBuilder dictionary2 = BIGINT.createBlockBuilder(null, dictionary1.getPositionCount());
    for (Slice expectedValue : dictionaryValues1) {
        BIGINT.writeLong(dictionary2, expectedValue.length());
    }
    DictionaryBlock commonSourceIdBlock2 = new DictionaryBlock(positionCount, dictionary2.build(), commonDictionaryIds, commonSourceId);
    // Create block with a different source id, dictionary size, used
    int otherDictionaryUsedPositions = 30;
    int[] otherDictionaryIds = getDictionaryIds(positionCount, otherDictionaryUsedPositions);
    Block dictionary3 = createSlicesBlock(createExpectedValues(70));
    DictionaryBlock randomSourceIdBlock = new DictionaryBlock(dictionary3, otherDictionaryIds);
    Page page = new Page(commonSourceIdBlock1, randomSourceIdBlock, commonSourceIdBlock2);
    page.compact();
    // dictionary blocks should all be compact
    assertTrue(((DictionaryBlock) page.getBlock(0)).isCompact());
    assertTrue(((DictionaryBlock) page.getBlock(1)).isCompact());
    assertTrue(((DictionaryBlock) page.getBlock(2)).isCompact());
    assertEquals(((DictionaryBlock) page.getBlock(0)).getDictionary().getPositionCount(), commonDictionaryUsedPositions);
    assertEquals(((DictionaryBlock) page.getBlock(1)).getDictionary().getPositionCount(), otherDictionaryUsedPositions);
    assertEquals(((DictionaryBlock) page.getBlock(2)).getDictionary().getPositionCount(), commonDictionaryUsedPositions);
    // Blocks that had the same source id before compacting page should have the same source id after compacting page
    assertNotEquals(((DictionaryBlock) page.getBlock(0)).getDictionarySourceId(), ((DictionaryBlock) page.getBlock(1)).getDictionarySourceId());
    assertEquals(((DictionaryBlock) page.getBlock(0)).getDictionarySourceId(), ((DictionaryBlock) page.getBlock(2)).getDictionarySourceId());
}
Also used : DictionaryId(com.facebook.presto.common.block.DictionaryId) DictionaryId.randomDictionaryId(com.facebook.presto.common.block.DictionaryId.randomDictionaryId) Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

Block (com.facebook.presto.common.block.Block)6 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)6 DictionaryId (com.facebook.presto.common.block.DictionaryId)6 DictionaryId.randomDictionaryId (com.facebook.presto.common.block.DictionaryId.randomDictionaryId)5 Test (org.testng.annotations.Test)3 Slice (io.airlift.slice.Slice)2 ArrayList (java.util.ArrayList)2 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)1 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)1 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)1 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)1 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)1 BlockAssertions.createSlicesBlock (com.facebook.presto.block.BlockAssertions.createSlicesBlock)1 BlockAssertions.createStringSequenceBlock (com.facebook.presto.block.BlockAssertions.createStringSequenceBlock)1 Page (com.facebook.presto.common.Page)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 GroupByHash.createGroupByHash (com.facebook.presto.operator.GroupByHash.createGroupByHash)1 TypeUtils.getHashBlock (com.facebook.presto.type.TypeUtils.getHashBlock)1 SizeOf.sizeOf (io.airlift.slice.SizeOf.sizeOf)1 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)1