Search in sources :

Example 26 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 27 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 28 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)

Example 29 with DictionaryBlock

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

the class TestDictionaryBlock method testCopyPositionsWithCompactionsAndReorder.

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

Example 30 with DictionaryBlock

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

the class TestDictionaryBlock method testCompact.

@Test
public void testCompact() throws Exception {
    Slice[] expectedValues = createExpectedValues(5);
    DictionaryBlock dictionaryBlock = createDictionaryBlockWithUnreferencedKeys(expectedValues, 10);
    assertEquals(dictionaryBlock.isCompact(), false);
    DictionaryBlock compactBlock = dictionaryBlock.compact();
    assertNotEquals(dictionaryBlock.getDictionarySourceId(), compactBlock.getDictionarySourceId());
    assertEquals(compactBlock.getDictionary().getPositionCount(), (expectedValues.length / 2) + 1);
    assertBlock(compactBlock.getDictionary(), new Slice[] { expectedValues[0], expectedValues[1], expectedValues[3] });
    assertDictionaryIds(compactBlock, 0, 1, 1, 2, 2, 0, 1, 1, 2, 2);
    assertEquals(compactBlock.isCompact(), true);
    DictionaryBlock reCompactedBlock = compactBlock.compact();
    assertEquals(reCompactedBlock.getDictionarySourceId(), compactBlock.getDictionarySourceId());
}
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