Search in sources :

Example 6 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryBlock method testBasicGetPositions.

@Test
public void testBasicGetPositions() {
    Slice[] expectedValues = createExpectedValues(10);
    Block dictionaryBlock = new DictionaryBlock(createSlicesBlock(expectedValues), new int[] { 0, 1, 2, 3, 4, 5 });
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[0], expectedValues[1], expectedValues[2], expectedValues[3], expectedValues[4], expectedValues[5] });
    DictionaryId dictionaryId = ((DictionaryBlock) dictionaryBlock).getDictionarySourceId();
    // first getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 8, 1, 2, 4, 5, 7, 9 }, 2, 4);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[4], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // second getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 1, 3, 0, 0 }, 0, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // third getPositions; we do not validate if -1 is an invalid position
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { -1, -1, 0, 1, 2 }, 2, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[2], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // mixed getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 0, 2, 2 }, 0, 3);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[1], expectedValues[5], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // duplicated getPositions
    dictionaryBlock = dictionaryBlock.getPositions(new int[] { 1, 1, 1, 1, 1 }, 0, 5);
    assertBlock(dictionaryBlock, TestDictionaryBlock::createBlockBuilder, new Slice[] { expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5], expectedValues[5] });
    assertEquals(((DictionaryBlock) dictionaryBlock).getDictionarySourceId(), dictionaryId);
    // out of range
    for (int position : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { position }, 0, 1);
            fail("Expected to fail");
        } catch (IllegalArgumentException e) {
            assertTrue(e.getMessage().startsWith("Invalid position"));
        }
    }
    for (int offset : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { 0 }, offset, 1);
            fail("Expected to fail");
        } catch (IndexOutOfBoundsException e) {
            assertTrue(e.getMessage().startsWith("Invalid offset"));
        }
    }
    for (int length : ImmutableList.of(-1, 6)) {
        try {
            dictionaryBlock.getPositions(new int[] { 0 }, 0, length);
            fail("Expected to fail");
        } catch (IndexOutOfBoundsException e) {
            assertTrue(e.getMessage().startsWith("Invalid offset"));
        }
    }
}
Also used : Slice(io.airlift.slice.Slice) DictionaryId(io.prestosql.spi.block.DictionaryId) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) BlockAssertions.createSlicesBlock(io.prestosql.block.BlockAssertions.createSlicesBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) Test(org.testng.annotations.Test)

Example 7 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

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) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 8 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestColumnarArray method assertDictionaryBlock.

private static <T> void assertDictionaryBlock(Block block, T[] expectedValues) {
    DictionaryBlock dictionaryBlock = createTestDictionaryBlock(block);
    T[] expectedDictionaryValues = createTestDictionaryExpectedValues(expectedValues);
    assertBlock(dictionaryBlock, expectedDictionaryValues);
    assertColumnarArray(dictionaryBlock, expectedDictionaryValues);
    assertRunLengthEncodedBlock(dictionaryBlock, expectedDictionaryValues);
}
Also used : ColumnarTestUtils.createTestDictionaryBlock(io.prestosql.block.ColumnarTestUtils.createTestDictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock)

Example 9 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryAwarePageFilter method testDictionaryBlockProcessingWithUnusedFailure.

@Test
public void testDictionaryBlockProcessingWithUnusedFailure() {
    // match some
    testFilter(createDictionaryBlockWithUnusedEntries(20, 100), DictionaryBlock.class);
    // match none
    testFilter(createDictionaryBlockWithUnusedEntries(20, 0), DictionaryBlock.class);
    // match all
    testFilter(new DictionaryBlock(createLongsBlock(4, 5, -1), new int[100]), DictionaryBlock.class);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Test(org.testng.annotations.Test)

Example 10 with DictionaryBlock

use of io.prestosql.spi.block.DictionaryBlock in project hetu-core by openlookeng.

the class TestDictionaryAwarePageFilter method createDictionaryBlock.

private static DictionaryBlock createDictionaryBlock(int dictionarySize, int blockSize) {
    Block dictionary = createLongSequenceBlock(0, dictionarySize);
    int[] ids = new int[blockSize];
    Arrays.setAll(ids, index -> index % dictionarySize);
    return new DictionaryBlock(dictionary, ids);
}
Also used : DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) LazyBlock(io.prestosql.spi.block.LazyBlock) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) LongArrayBlock(io.prestosql.spi.block.LongArrayBlock) BlockAssertions.createLongsBlock(io.prestosql.block.BlockAssertions.createLongsBlock) BlockAssertions.createLongSequenceBlock(io.prestosql.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block)

Aggregations

DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)69 Block (io.prestosql.spi.block.Block)31 Test (org.testng.annotations.Test)29 Slice (io.airlift.slice.Slice)17 BlockBuilder (io.prestosql.spi.block.BlockBuilder)16 RunLengthEncodedBlock (io.prestosql.spi.block.RunLengthEncodedBlock)11 Page (io.prestosql.spi.Page)9 ColumnarTestUtils.assertBlock (io.prestosql.block.ColumnarTestUtils.assertBlock)8 LazyBlock (io.prestosql.spi.block.LazyBlock)8 LongArrayBlock (io.prestosql.spi.block.LongArrayBlock)8 PageBuilderStatus (io.prestosql.spi.block.PageBuilderStatus)8 BlockAssertions.createLongSequenceBlock (io.prestosql.block.BlockAssertions.createLongSequenceBlock)7 DictionaryId (io.prestosql.spi.block.DictionaryId)6 TestUnnesterUtil.createSimpleBlock (io.prestosql.operator.unnest.TestUnnesterUtil.createSimpleBlock)5 DictionaryId.randomDictionaryId (io.prestosql.spi.block.DictionaryId.randomDictionaryId)5 BlockAssertions.createLongsBlock (io.prestosql.block.BlockAssertions.createLongsBlock)4 BlockAssertions.createLongDictionaryBlock (io.prestosql.block.BlockAssertions.createLongDictionaryBlock)3 ColumnarTestUtils.createTestDictionaryBlock (io.prestosql.block.ColumnarTestUtils.createTestDictionaryBlock)3 DriverYieldSignal (io.prestosql.operator.DriverYieldSignal)3 JoinProbeFactory (io.prestosql.operator.JoinProbe.JoinProbeFactory)3