Search in sources :

Example 16 with DictionaryBlock

use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.

the class MultiChannelGroupByHash method addDictionaryPage.

private void addDictionaryPage(Page page) {
    verify(canProcessDictionary(page), "invalid call to addDictionaryPage");
    DictionaryBlock dictionaryBlock = (DictionaryBlock) page.getBlock(channels[0]);
    updateDictionaryLookBack(dictionaryBlock.getDictionary());
    Page dictionaryPage = createPageWithExtractedDictionary(page);
    for (int i = 0; i < page.getPositionCount(); i++) {
        int positionInDictionary = dictionaryBlock.getId(i);
        getGroupId(hashGenerator, dictionaryPage, positionInDictionary);
    }
}
Also used : DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Page(com.facebook.presto.spi.Page)

Example 17 with DictionaryBlock

use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.

the class BlockAssertions method createLongDictionaryBlock.

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

Example 18 with DictionaryBlock

use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.

the class TestDictionaryBlock method testSizeInBytes.

@Test
public void testSizeInBytes() throws Exception {
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    assertEquals(dictionaryBlock.getSizeInBytes(), dictionaryBlock.getDictionary().getSizeInBytes() + (100 * SIZE_OF_INT));
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 19 with DictionaryBlock

use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.

the class TestDictionaryBlock method testCompactAllKeysReferenced.

@Test
public void testCompactAllKeysReferenced() throws Exception {
    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(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 20 with DictionaryBlock

use of com.facebook.presto.spi.block.DictionaryBlock in project presto by prestodb.

the class TestDictionaryBlock method createDictionaryBlock.

private static DictionaryBlock createDictionaryBlock(Slice[] expectedValues, int positionCount) {
    int dictionarySize = expectedValues.length;
    int[] ids = new int[positionCount];
    for (int i = 0; i < positionCount; i++) {
        ids[i] = i % dictionarySize;
    }
    return new DictionaryBlock(positionCount, new SliceArrayBlock(dictionarySize, expectedValues), ids);
}
Also used : SliceArrayBlock(com.facebook.presto.spi.block.SliceArrayBlock) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock)

Aggregations

DictionaryBlock (com.facebook.presto.spi.block.DictionaryBlock)32 Block (com.facebook.presto.spi.block.Block)12 Test (org.testng.annotations.Test)12 Slice (io.airlift.slice.Slice)9 Page (com.facebook.presto.spi.Page)7 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)6 BlockBuilderStatus (com.facebook.presto.spi.block.BlockBuilderStatus)5 DictionaryId (com.facebook.presto.spi.block.DictionaryId)5 DictionaryId.randomDictionaryId (com.facebook.presto.spi.block.DictionaryId.randomDictionaryId)5 LazyBlock (com.facebook.presto.spi.block.LazyBlock)5 RunLengthEncodedBlock (com.facebook.presto.spi.block.RunLengthEncodedBlock)5 SliceArrayBlock (com.facebook.presto.spi.block.SliceArrayBlock)5 BlockAssertions.createLongDictionaryBlock (com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock)4 PageProcessor (com.facebook.presto.operator.PageProcessor)3 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)3 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)3 InputReferenceExpression (com.facebook.presto.sql.relational.InputReferenceExpression)3 Signature (com.facebook.presto.metadata.Signature)2 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)2 CallExpression (com.facebook.presto.sql.relational.CallExpression)2