Search in sources :

Example 1 with TypeTestUtils.getHashBlock

use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.

the class TestGroupByHash method testAppendTo.

@Test
public void testAppendTo() {
    Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    Work<GroupByIdBlock> work = groupByHash.getGroupIds(new Page(valuesBlock, hashBlock));
    work.process();
    GroupByIdBlock groupIds = work.getResult();
    for (int i = 0; i < groupIds.getPositionCount(); i++) {
        assertEquals(groupIds.getGroupId(i), i);
    }
    assertEquals(groupByHash.getGroupCount(), 100);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page page = pageBuilder.build();
    // Ensure that all blocks have the same positionCount
    for (int i = 0; i < groupByHash.getTypes().size(); i++) {
        assertEquals(page.getBlock(i).getPositionCount(), 100);
    }
    assertEquals(page.getPositionCount(), 100);
    BlockAssertions.assertBlockEquals(VARCHAR, page.getBlock(0), valuesBlock);
    BlockAssertions.assertBlockEquals(BIGINT, page.getBlock(1), hashBlock);
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) Test(org.testng.annotations.Test)

Example 2 with TypeTestUtils.getHashBlock

use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.

the class TestGroupByHash method testAppendToMultipleTuplesPerGroup.

@Test
public void testAppendToMultipleTuplesPerGroup() {
    List<Long> values = new ArrayList<>();
    for (long i = 0; i < 100; i++) {
        values.add(i % 50);
    }
    Block valuesBlock = BlockAssertions.createLongsBlock(values);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    assertEquals(groupByHash.getGroupCount(), 50);
    PageBuilder pageBuilder = new PageBuilder(groupByHash.getTypes());
    for (int i = 0; i < groupByHash.getGroupCount(); i++) {
        pageBuilder.declarePosition();
        groupByHash.appendValuesTo(i, pageBuilder, 0);
    }
    Page outputPage = pageBuilder.build();
    assertEquals(outputPage.getPositionCount(), 50);
    BlockAssertions.assertBlockEquals(BIGINT, outputPage.getBlock(0), BlockAssertions.createLongSequenceBlock(0, 50));
}
Also used : ArrayList(java.util.ArrayList) GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) PageBuilder(io.trino.spi.PageBuilder) Test(org.testng.annotations.Test)

Example 3 with TypeTestUtils.getHashBlock

use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.

the class TestGroupByHash method testContains.

@Test
public void testContains() {
    Block valuesBlock = BlockAssertions.createDoubleSequenceBlock(0, 10);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), valuesBlock);
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(DOUBLE), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    Block testBlock = BlockAssertions.createDoublesBlock((double) 3);
    Block testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
    assertTrue(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
    testBlock = BlockAssertions.createDoublesBlock(11.0);
    testHashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(DOUBLE), testBlock);
    assertFalse(groupByHash.contains(0, new Page(testBlock, testHashBlock), CONTAINS_CHANNELS));
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 4 with TypeTestUtils.getHashBlock

use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.

the class TestGroupByHash method testRunLengthEncodedBigintGroupByHash.

@Test
public void testRunLengthEncodedBigintGroupByHash() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    Block block = BlockAssertions.createLongsBlock(0L);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
    Page page = new Page(new RunLengthEncodedBlock(block, 2), new RunLengthEncodedBlock(hashBlock, 2));
    groupByHash.addPage(page).process();
    assertEquals(groupByHash.getGroupCount(), 1);
    Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
    work.process();
    GroupByIdBlock groupIds = work.getResult();
    assertEquals(groupIds.getGroupCount(), 1);
    assertEquals(groupIds.getPositionCount(), 2);
    assertEquals(groupIds.getGroupId(0), 0);
    assertEquals(groupIds.getGroupId(1), 0);
    List<Block> children = groupIds.getChildren();
    assertEquals(children.size(), 1);
    assertTrue(children.get(0) instanceof RunLengthEncodedBlock);
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) Test(org.testng.annotations.Test)

Example 5 with TypeTestUtils.getHashBlock

use of io.trino.type.TypeTestUtils.getHashBlock in project trino by trinodb.

the class TestGroupByHash method testForceRehash.

@Test
public void testForceRehash() {
    // Create a page with positionCount >> expected size of groupByHash
    Block valuesBlock = BlockAssertions.createStringSequenceBlock(0, 100);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(VARCHAR), valuesBlock);
    // Create group by hash with extremely small size
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(VARCHAR), new int[] { 0 }, Optional.of(1), 4, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    groupByHash.getGroupIds(new Page(valuesBlock, hashBlock)).process();
    // Ensure that all groups are present in group by hash
    for (int i = 0; i < valuesBlock.getPositionCount(); i++) {
        assertTrue(groupByHash.contains(i, new Page(valuesBlock, hashBlock), CONTAINS_CHANNELS));
    }
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) TypeTestUtils.getHashBlock(io.trino.type.TypeTestUtils.getHashBlock) BlockAssertions.createLongSequenceBlock(io.trino.block.BlockAssertions.createLongSequenceBlock) DictionaryBlock(io.trino.spi.block.DictionaryBlock) BlockAssertions.createStringSequenceBlock(io.trino.block.BlockAssertions.createStringSequenceBlock) Block(io.trino.spi.block.Block) RunLengthEncodedBlock(io.trino.spi.block.RunLengthEncodedBlock) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Aggregations

BlockAssertions.createLongSequenceBlock (io.trino.block.BlockAssertions.createLongSequenceBlock)9 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)9 BlockAssertions.createStringSequenceBlock (io.trino.block.BlockAssertions.createStringSequenceBlock)9 GroupByHash.createGroupByHash (io.trino.operator.GroupByHash.createGroupByHash)9 Page (io.trino.spi.Page)9 Block (io.trino.spi.block.Block)9 DictionaryBlock (io.trino.spi.block.DictionaryBlock)9 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)9 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)9 TypeTestUtils.getHashBlock (io.trino.type.TypeTestUtils.getHashBlock)9 Test (org.testng.annotations.Test)9 PageBuilder (io.trino.spi.PageBuilder)2 ArrayList (java.util.ArrayList)1