Search in sources :

Example 1 with JoinProbeFactory

use of io.prestosql.operator.JoinProbe.JoinProbeFactory in project hetu-core by openlookeng.

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, 0), i * 2);
        assertEquals(output.getBlock(1).getLong(i, 0), 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, 0), i);
        assertEquals(output.getBlock(1).getLong(i, 0), 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, 0), i);
        assertEquals(output.getBlock(1).getLong(i - 10, 0), i);
    }
}
Also used : JoinProbeFactory(io.prestosql.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 2 with JoinProbeFactory

use of io.prestosql.operator.JoinProbe.JoinProbeFactory in project hetu-core by openlookeng.

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, 0), i / 2);
        assertEquals(output.getBlock(1).getLong(i, 0), i / 2);
        if (i % 2 == 0) {
            assertFalse(output.getBlock(2).isNull(i));
            assertFalse(output.getBlock(3).isNull(i));
            assertEquals(output.getBlock(2).getLong(i, 0), i / 2);
            assertEquals(output.getBlock(3).getLong(i, 0), 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(io.prestosql.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 3 with JoinProbeFactory

use of io.prestosql.operator.JoinProbe.JoinProbeFactory in project hetu-core by openlookeng.

the class TestLookupJoinPageBuilder method testPageBuilderSnapshot.

@Test
public void testPageBuilderSnapshot() {
    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));
    PagesSerde serde = TestingPagesSerdeFactory.testingPagesSerde();
    Object initialState = lookupJoinPageBuilder.capture(serde);
    int joinPosition = 0;
    while (!lookupJoinPageBuilder.isFull() && probe.advanceNextPosition()) {
        lookupJoinPageBuilder.appendRow(probe, lookupSource, joinPosition++);
        lookupJoinPageBuilder.appendNullForBuild(probe);
    }
    assertFalse(lookupJoinPageBuilder.isEmpty());
    // Compare state
    Object snapshot = lookupJoinPageBuilder.capture(serde);
    assertEquals(SnapshotTestUtil.toSimpleSnapshotMapping(snapshot), createExpectedMapping());
    // Restore to initial state and repopulate, then compare resulting page with expected output.
    lookupJoinPageBuilder.restore(initialState, serde);
    probe = joinProbeFactory.createJoinProbe(page);
    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, 0), i / 2);
        assertEquals(output.getBlock(1).getLong(i, 0), i / 2);
        if (i % 2 == 0) {
            assertFalse(output.getBlock(2).isNull(i));
            assertFalse(output.getBlock(3).isNull(i));
            assertEquals(output.getBlock(2).getLong(i, 0), i / 2);
            assertEquals(output.getBlock(3).getLong(i, 0), 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 : PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) JoinProbeFactory(io.prestosql.operator.JoinProbe.JoinProbeFactory) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) DictionaryBlock(io.prestosql.spi.block.DictionaryBlock) Block(io.prestosql.spi.block.Block) Page(io.prestosql.spi.Page) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Example 4 with JoinProbeFactory

use of io.prestosql.operator.JoinProbe.JoinProbeFactory in project hetu-core by openlookeng.

the class TestLookupJoinPageBuilder method testCrossJoinWithEmptyBuild.

@Test
public void testCrossJoinWithEmptyBuild() {
    BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1);
    BIGINT.writeLong(blockBuilder, 0);
    Page page = new Page(blockBuilder.build());
    // nothing on the build side so we don't append anything
    LookupSource lookupSource = new TestLookupSource(ImmutableList.of(), page);
    JoinProbe probe = (new JoinProbeFactory(new int[] { 0 }, ImmutableList.of(0), OptionalInt.empty())).createJoinProbe(page);
    LookupJoinPageBuilder lookupJoinPageBuilder = new LookupJoinPageBuilder(ImmutableList.of(BIGINT));
    // append the same row many times should also flush in the end
    probe.advanceNextPosition();
    for (int i = 0; i < 300_000; i++) {
        lookupJoinPageBuilder.appendRow(probe, lookupSource, 0);
    }
    assertTrue(lookupJoinPageBuilder.isFull());
}
Also used : JoinProbeFactory(io.prestosql.operator.JoinProbe.JoinProbeFactory) Page(io.prestosql.spi.Page) BlockBuilder(io.prestosql.spi.block.BlockBuilder) Test(org.testng.annotations.Test)

Aggregations

JoinProbeFactory (io.prestosql.operator.JoinProbe.JoinProbeFactory)4 Page (io.prestosql.spi.Page)4 BlockBuilder (io.prestosql.spi.block.BlockBuilder)4 Test (org.testng.annotations.Test)4 Block (io.prestosql.spi.block.Block)3 DictionaryBlock (io.prestosql.spi.block.DictionaryBlock)3 PagesSerde (io.hetu.core.transport.execution.buffer.PagesSerde)1