Search in sources :

Example 66 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestDictionaryBlock method testCopyRegionCreatesCompactBlock.

@Test
public void testCopyRegionCreatesCompactBlock() {
    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) 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 67 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestDictionaryBlock method testCopyPositionsNoCompaction.

@Test
public void testCopyPositionsNoCompaction() {
    Slice[] expectedValues = createExpectedValues(1);
    DictionaryBlock dictionaryBlock = createDictionaryBlock(expectedValues, 100);
    int[] positionsToCopy = new int[] { 0, 2, 4, 5 };
    DictionaryBlock copiedBlock = (DictionaryBlock) dictionaryBlock.copyPositions(positionsToCopy, 0, positionsToCopy.length);
    assertEquals(copiedBlock.getPositionCount(), positionsToCopy.length);
    assertBlock(copiedBlock.getDictionary(), TestDictionaryBlock::createBlockBuilder, expectedValues);
}
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 68 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestDictionaryBlock method testCompactGetPositions.

@Test
public void testCompactGetPositions() {
    DictionaryBlock block = new DictionaryBlock(createSlicesBlock(createExpectedValues(10)), new int[] { 0, 1, 2, 3, 4, 5 }).compact();
    // 3, 3, 4, 5, 2, 0, 1, 1
    block = (DictionaryBlock) block.getPositions(new int[] { 3, 3, 4, 5, 2, 0, 1, 1 }, 0, 7);
    assertTrue(block.isCompact());
    // 3, 3, 4, 5, 2, 0, 1, 1, 0, 2, 5, 4, 3
    block = (DictionaryBlock) block.getPositions(new int[] { 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1 }, 0, 12);
    assertTrue(block.isCompact());
    // 3, 4, 3, 4, 3
    block = (DictionaryBlock) block.getPositions(new int[] { 0, 2, 0, 2, 0 }, 0, 5);
    assertFalse(block.isCompact());
    block = block.compact();
    // 3, 4, 4, 4
    block = (DictionaryBlock) block.getPositions(new int[] { 0, 1, 1, 1 }, 0, 4);
    assertTrue(block.isCompact());
    // 4, 4, 4, 4
    block = (DictionaryBlock) block.getPositions(new int[] { 1, 1, 1, 1 }, 0, 4);
    assertFalse(block.isCompact());
    block = block.compact();
    // 4
    block = (DictionaryBlock) block.getPositions(new int[] { 0 }, 0, 1);
    assertTrue(block.isCompact());
    // empty
    block = (DictionaryBlock) block.getPositions(new int[] {}, 0, 0);
    assertFalse(block.isCompact());
    block = block.compact();
    // empty
    block = (DictionaryBlock) block.getPositions(new int[] {}, 0, 0);
    assertTrue(block.isCompact());
}
Also used : BlockAssertions.createRandomDictionaryBlock(com.facebook.presto.block.BlockAssertions.createRandomDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 69 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

the class TestDictionaryBlock method testNonCachedLogicalBytes.

@Test
public void testNonCachedLogicalBytes() {
    int numEntries = 10;
    BlockBuilder blockBuilder = VARCHAR.createBlockBuilder(null, numEntries);
    // Over allocate dictionary indexes but only use the required limit.
    int[] dictionaryIndexes = new int[numEntries + 10];
    Arrays.fill(dictionaryIndexes, 1);
    blockBuilder.appendNull();
    dictionaryIndexes[0] = 0;
    String string = "";
    for (int i = 1; i < numEntries; i++) {
        string += "a";
        VARCHAR.writeSlice(blockBuilder, utf8Slice(string));
        dictionaryIndexes[i] = numEntries - i;
    }
    // A dictionary block of size 10, 1st element -> null, 2nd element size -> 9....9th element size -> 1
    // Pass different maxChunkSize and different offset and verify if it computes the chunk lengths correctly.
    Block elementBlock = blockBuilder.build();
    DictionaryBlock block = new DictionaryBlock(numEntries, elementBlock, dictionaryIndexes);
    int elementSize = Integer.BYTES + Byte.BYTES;
    long size = block.getRegionLogicalSizeInBytes(0, 1);
    assertEquals(size, 0 + 1 * elementSize);
    size = block.getRegionLogicalSizeInBytes(0, numEntries);
    assertEquals(size, 45 + numEntries * elementSize);
    size = block.getRegionLogicalSizeInBytes(1, 2);
    assertEquals(size, 9 + 8 + 2 * elementSize);
    size = block.getRegionLogicalSizeInBytes(9, 1);
    assertEquals(size, 1 + 1 * elementSize);
}
Also used : 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) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) VariableWidthBlockBuilder(com.facebook.presto.common.block.VariableWidthBlockBuilder) Test(org.testng.annotations.Test)

Example 70 with DictionaryBlock

use of com.facebook.presto.common.block.DictionaryBlock in project urban-eureka by errir503.

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