Search in sources :

Example 86 with DictionaryBlock

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

the class TestLookupJoinPageBuilder method testPageBuilder.

@Test
public void testPageBuilder() {
    int entries = 10_000;
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, entries);
    for (int i = 0; i < entries; i++) {
        BIGINT.writeLong(blockBuilder, i);
    }
    Block block = blockBuilder.build();
    Page page = new Page(block, block);
    JoinProbeFactory joinProbeFactory = new JoinProbeFactory(new int[] { 0, 1 }, ImmutableList.of(0, 1), OptionalInt.empty());
    JoinProbe probe = joinProbeFactory.createJoinProbe(page);
    LookupSource lookupSource = new TestLookupSource(ImmutableList.of(BIGINT, BIGINT), page);
    LookupJoinPageBuilder lookupJoinPageBuilder = new LookupJoinPageBuilder(ImmutableList.of(BIGINT, BIGINT));
    int joinPosition = 0;
    while (!lookupJoinPageBuilder.isFull() && probe.advanceNextPosition()) {
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition++);
        lookupJoinPageBuilder.appendNullForBuild(probe);
    }
    assertFalse(lookupJoinPageBuilder.isEmpty());
    Page output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 4);
    assertTrue(output.getBlock(0) instanceof DictionaryBlock);
    assertTrue(output.getBlock(1) instanceof DictionaryBlock);
    for (int i = 0; i < output.getPositionCount(); i++) {
        assertFalse(output.getBlock(0).isNull(i));
        assertFalse(output.getBlock(1).isNull(i));
        assertEquals(output.getBlock(0).getLong(i), i / 2);
        assertEquals(output.getBlock(1).getLong(i), i / 2);
        if (i % 2 == 0) {
            assertFalse(output.getBlock(2).isNull(i));
            assertFalse(output.getBlock(3).isNull(i));
            assertEquals(output.getBlock(2).getLong(i), i / 2);
            assertEquals(output.getBlock(3).getLong(i), i / 2);
        } else {
            assertTrue(output.getBlock(2).isNull(i));
            assertTrue(output.getBlock(3).isNull(i));
        }
    }
    assertTrue(lookupJoinPageBuilder.toString().contains("positionCount=" + output.getPositionCount()));
    lookupJoinPageBuilder.reset();
    assertTrue(lookupJoinPageBuilder.isEmpty());
}
Also used : JoinProbeFactory(com.facebook.presto.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 87 with DictionaryBlock

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

the class TestLookupJoinPageBuilder method testDifferentPositions.

@Test
public void testDifferentPositions() {
    int entries = 100;
    BlockBuilder blockBuilder = BIGINT.createFixedSizeBlockBuilder(entries);
    for (int i = 0; i < entries; i++) {
        BIGINT.writeLong(blockBuilder, i);
    }
    Block block = blockBuilder.build();
    Page page = new Page(block);
    JoinProbeFactory joinProbeFactory = new JoinProbeFactory(new int[] { 0 }, ImmutableList.of(0), OptionalInt.empty());
    LookupSource lookupSource = new TestLookupSource(ImmutableList.of(BIGINT), page);
    LookupJoinPageBuilder lookupJoinPageBuilder = new LookupJoinPageBuilder(ImmutableList.of(BIGINT));
    // empty
    JoinProbe probe = joinProbeFactory.createJoinProbe(page);
    Page output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertTrue(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), 0);
    lookupJoinPageBuilder.reset();
    // the probe covers non-sequential positions
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        if (joinPosition % 2 == 1) {
            continue;
        }
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertTrue(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), entries / 2);
    for (int i = 0; i < entries / 2; i++) {
        assertEquals(output.getBlock(0).getLong(i), i * 2);
        assertEquals(output.getBlock(1).getLong(i), i * 2);
    }
    lookupJoinPageBuilder.reset();
    // the probe covers everything
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertFalse(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), entries);
    for (int i = 0; i < entries; i++) {
        assertEquals(output.getBlock(0).getLong(i), i);
        assertEquals(output.getBlock(1).getLong(i), i);
    }
    lookupJoinPageBuilder.reset();
    // the probe covers some sequential positions
    probe = joinProbeFactory.createJoinProbe(page);
    for (int joinPosition = 0; probe.advanceNextPosition(); joinPosition++) {
        if (joinPosition < 10 || joinPosition >= 50) {
            continue;
        }
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition);
    }
    output = lookupJoinPageBuilder.build(probe);
    assertEquals(output.getChannelCount(), 2);
    assertFalse(output.getBlock(0) instanceof DictionaryBlock);
    assertEquals(output.getPositionCount(), 40);
    for (int i = 10; i < 50; i++) {
        assertEquals(output.getBlock(0).getLong(i - 10), i);
        assertEquals(output.getBlock(1).getLong(i - 10), i);
    }
}
Also used : JoinProbeFactory(com.facebook.presto.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 88 with DictionaryBlock

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

the class Page method getRelatedDictionaryBlocks.

private Map<DictionaryId, DictionaryBlockIndexes> getRelatedDictionaryBlocks() {
    Map<DictionaryId, DictionaryBlockIndexes> relatedDictionaryBlocks = new HashMap<>();
    for (int i = 0; i < blocks.length; i++) {
        Block block = blocks[i];
        if (block instanceof DictionaryBlock) {
            DictionaryBlock dictionaryBlock = (DictionaryBlock) block;
            relatedDictionaryBlocks.computeIfAbsent(dictionaryBlock.getDictionarySourceId(), id -> new DictionaryBlockIndexes()).addBlock(dictionaryBlock, i);
        }
    }
    return relatedDictionaryBlocks;
}
Also used : DictionaryId(com.facebook.presto.common.block.DictionaryId) Arrays(java.util.Arrays) IdentityHashMap(java.util.IdentityHashMap) Set(java.util.Set) HashMap(java.util.HashMap) Math.min(java.lang.Math.min) String.format(java.lang.String.format) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) Collections.newSetFromMap(java.util.Collections.newSetFromMap) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) ClassLayout(org.openjdk.jol.info.ClassLayout) SizeOf.sizeOf(io.airlift.slice.SizeOf.sizeOf) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) DictionaryId.randomDictionaryId(com.facebook.presto.common.block.DictionaryId.randomDictionaryId) Block(com.facebook.presto.common.block.Block) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) DictionaryId(com.facebook.presto.common.block.DictionaryId) DictionaryId.randomDictionaryId(com.facebook.presto.common.block.DictionaryId.randomDictionaryId) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block)

Example 89 with DictionaryBlock

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

the class TestColumnarMap method assertDictionaryBlock.

private static void assertDictionaryBlock(Block block, Slice[][][] expectedValues) {
    DictionaryBlock dictionaryBlock = createTestDictionaryBlock(block);
    Slice[][][] expectedDictionaryValues = createTestDictionaryExpectedValues(expectedValues);
    assertBlock(dictionaryBlock, expectedDictionaryValues);
    assertColumnarMap(dictionaryBlock, expectedDictionaryValues);
    assertRunLengthEncodedBlock(dictionaryBlock, expectedDictionaryValues);
}
Also used : Slice(io.airlift.slice.Slice) ColumnarTestUtils.createTestDictionaryBlock(com.facebook.presto.block.ColumnarTestUtils.createTestDictionaryBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock)

Example 90 with DictionaryBlock

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

the class TestColumnarRow method assertDictionaryBlock.

private static <T> void assertDictionaryBlock(Block block, T[] expectedValues) {
    DictionaryBlock dictionaryBlock = createTestDictionaryBlock(block);
    T[] expectedDictionaryValues = createTestDictionaryExpectedValues(expectedValues);
    assertBlock(dictionaryBlock, expectedDictionaryValues);
    assertColumnarRow(dictionaryBlock, expectedDictionaryValues);
    assertRunLengthEncodedBlock(dictionaryBlock, expectedDictionaryValues);
}
Also used : DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) ColumnarTestUtils.createTestDictionaryBlock(com.facebook.presto.block.ColumnarTestUtils.createTestDictionaryBlock)

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