Search in sources :

Example 96 with DictionaryBlock

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

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) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 97 with DictionaryBlock

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

the class TestDictionaryBlock method testCompact.

@Test
public void testCompact() {
    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(), TestDictionaryBlock::createBlockBuilder, 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) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 98 with DictionaryBlock

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

the class TestDictionaryBlock method testLogicalSizeInBytes.

@Test
public void testLogicalSizeInBytes() {
    // The 10 Slices in the array will be of lengths 0 to 9.
    Slice[] expectedValues = createExpectedValues(10);
    // The dictionary within the dictionary block is expected to be a VariableWidthBlock of size 95 bytes.
    // 45 bytes for the expectedValues Slices (sum of seq(0,9)) and 50 bytes for the position and isNull array (total 10 positions).
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    assertEquals(dictionaryBlock.getDictionary().getLogicalSizeInBytes(), 95);
    // The 100 positions in the dictionary block index to 10 positions in the underlying dictionary (10 each).
    // Logical size calculation accounts for 4 bytes of offset and 1 byte of isNull. Therefore the expected unoptimized
    // size is 10 times the size of the underlying dictionary (VariableWidthBlock).
    assertEquals(dictionaryBlock.getLogicalSizeInBytes(), 95 * 10);
    // With alternating nulls, we have 21 positions, with the same size calculation as above.
    dictionaryBlock = createDictionaryBlock(alternatingNullValues(expectedValues), 210);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 21);
    assertEquals(dictionaryBlock.getDictionary().getLogicalSizeInBytes(), 150);
    // The null positions should be included in the logical size.
    assertEquals(dictionaryBlock.getLogicalSizeInBytes(), 150 * 10);
    Block longArrayBlock = createRandomLongsBlock(100, 0.5f);
    DictionaryBlock dictionaryDictionaryBlock = createRandomDictionaryBlock(createRandomDictionaryBlock(longArrayBlock, 50), 10);
    assertEquals(dictionaryDictionaryBlock.getDictionary().getLogicalSizeInBytes(), 450);
    assertEquals(dictionaryDictionaryBlock.getLogicalSizeInBytes(), 90);
    DictionaryBlock dictionaryRleBlock = createRandomDictionaryBlock(createRLEBlock(1, 50), 10);
    assertEquals(dictionaryRleBlock.getDictionary().getLogicalSizeInBytes(), 450);
    assertEquals(dictionaryRleBlock.getLogicalSizeInBytes(), 90);
}
Also used : Slice(io.airlift.slice.Slice) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) BlockAssertions.createSlicesBlock(com.facebook.presto.block.BlockAssertions.createSlicesBlock) BlockAssertions.createRandomLongsBlock(com.facebook.presto.block.BlockAssertions.createRandomLongsBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) IntArrayBlock(com.facebook.presto.common.block.IntArrayBlock) BlockAssertions.createRLEBlock(com.facebook.presto.block.BlockAssertions.createRLEBlock) Block(com.facebook.presto.common.block.Block) Test(org.testng.annotations.Test)

Example 99 with DictionaryBlock

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

the class TestDictionaryBlock method testSizeInBytes.

@Test
public void testSizeInBytes() {
    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) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 100 with DictionaryBlock

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

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) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Aggregations

DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)125 Test (org.testng.annotations.Test)66 Block (com.facebook.presto.common.block.Block)65 BlockAssertions.createRandomDictionaryBlock (com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock)32 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)28 Slice (io.airlift.slice.Slice)26 Page (com.facebook.presto.common.Page)25 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)22 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)22 BlockAssertions.createLongSequenceBlock (com.facebook.presto.block.BlockAssertions.createLongSequenceBlock)14 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)14 DictionaryId (com.facebook.presto.common.block.DictionaryId)12 LazyBlock (com.facebook.presto.common.block.LazyBlock)12 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)10 BlockAssertions.createRLEBlock (com.facebook.presto.block.BlockAssertions.createRLEBlock)10 BlockAssertions.createRandomLongsBlock (com.facebook.presto.block.BlockAssertions.createRandomLongsBlock)10 BlockAssertions.createSlicesBlock (com.facebook.presto.block.BlockAssertions.createSlicesBlock)10 DictionaryId.randomDictionaryId (com.facebook.presto.common.block.DictionaryId.randomDictionaryId)10 IntArrayBlock (com.facebook.presto.common.block.IntArrayBlock)8 Type (com.facebook.presto.common.type.Type)8