Search in sources :

Example 21 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyRegionCreatesCompactBlock.

@Test
public void testCopyRegionCreatesCompactBlock() throws Exception {
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    DictionaryBlock copyRegionDictionaryBlock = (DictionaryBlock) dictionaryBlock.copyRegion(1, 3);
    assertTrue(copyRegionDictionaryBlock.isCompact());
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 22 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsSamePosition.

@Test
public void testCopyPositionsSamePosition() throws Exception {
    Slice[] expectedValues = createExpectedValues(10);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    List<Integer> positionsToCopy = Ints.asList(52, 52, 52);
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
    assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
    assertBlock(copiedBlock.getDictionary(), new Slice[] { expectedValues[2] });
    assertDictionaryIds(copiedBlock, 0, 0, 0);
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 23 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsNoCompaction.

@Test
public void testCopyPositionsNoCompaction() throws Exception {
    Slice[] expectedValues = createExpectedValues(1);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    List<Integer> positionsToCopy = Ints.asList(0, 2, 4, 5);
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
    assertBlock(copiedBlock.getDictionary(), expectedValues);
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 24 with DictionaryBlock

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

the class TestDictionaryBlock method createDictionaryBlockWithUnreferencedKeys.

private static DictionaryBlock createDictionaryBlockWithUnreferencedKeys(Slice[] expectedValues, int positionCount) {
    // adds references to 0 and all odd indexes
    int dictionarySize = expectedValues.length;
    int[] ids = new int[positionCount];
    for (int i = 0; i < positionCount; i++) {
        int index = i % dictionarySize;
        if (index % 2 == 0 && index != 0) {
            index--;
        }
        ids[i] = index;
    }
    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)

Example 25 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsWithCompaction.

@Test
public void testCopyPositionsWithCompaction() throws Exception {
    Slice[] expectedValues = createExpectedValues(10);
    Slice firstExpectedValue = expectedValues[0];
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    List<Integer> positionsToCopy = Ints.asList(0, 10, 20, 30, 40);
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy);
    assertEquals(copiedBlock.getDictionary().getPositionCount(), 1);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.size());
    assertBlock(copiedBlock.getDictionary(), new Slice[] { firstExpectedValue });
    assertBlock(copiedBlock, new Slice[] { firstExpectedValue, firstExpectedValue, firstExpectedValue, firstExpectedValue, firstExpectedValue });
}
Also used : Slice(io.airlift.slice.Slice) DictionaryBlock(com.facebook.presto.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

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