Search in sources :

Example 1 with BlockAssertions.createLongsBlock

use of io.trino.block.BlockAssertions.createLongsBlock in project trino by trinodb.

the class TestGroupByHash method testProperWorkTypesSelected.

@Test
public void testProperWorkTypesSelected() {
    Block bigintBlock = BlockAssertions.createLongsBlock(1, 2, 3, 4, 5, 6, 7, 8);
    Block bigintDictionaryBlock = BlockAssertions.createLongDictionaryBlock(0, 8);
    Block bigintRleBlock = BlockAssertions.createRLEBlock(42, 8);
    Block varcharBlock = BlockAssertions.createStringsBlock("1", "2", "3", "4", "5", "6", "7", "8");
    Block varcharDictionaryBlock = BlockAssertions.createStringDictionaryBlock(1, 8);
    Block varcharRleBlock = new RunLengthEncodedBlock(new VariableWidthBlock(1, Slices.EMPTY_SLICE, new int[] { 0, 1 }, Optional.empty()), 8);
    Block bigintBigDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 8, 1000);
    Block bigintSingletonDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 1);
    // Above Short.MAX_VALUE
    Block bigintHugeDictionaryBlock = BlockAssertions.createLongDictionaryBlock(1, 500000, 66000);
    Page singleBigintPage = new Page(bigintBlock);
    assertGroupByHashWork(singleBigintPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetGroupIdsWork.class);
    Page singleBigintDictionaryPage = new Page(bigintDictionaryBlock);
    assertGroupByHashWork(singleBigintDictionaryPage, ImmutableList.of(BIGINT), BigintGroupByHash.GetDictionaryGroupIdsWork.class);
    Page singleBigintRlePage = new Page(bigintRleBlock);
    assertGroupByHashWork(singleBigintRlePage, ImmutableList.of(BIGINT), BigintGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
    Page singleVarcharPage = new Page(varcharBlock);
    assertGroupByHashWork(singleVarcharPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
    Page singleVarcharDictionaryPage = new Page(varcharDictionaryBlock);
    assertGroupByHashWork(singleVarcharDictionaryPage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetDictionaryGroupIdsWork.class);
    Page singleVarcharRlePage = new Page(varcharRleBlock);
    assertGroupByHashWork(singleVarcharRlePage, ImmutableList.of(VARCHAR), MultiChannelGroupByHash.GetRunLengthEncodedGroupIdsWork.class);
    Page lowCardinalityDictionaryPage = new Page(bigintDictionaryBlock, varcharDictionaryBlock);
    assertGroupByHashWork(lowCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetLowCardinalityDictionaryGroupIdsWork.class);
    Page highCardinalityDictionaryPage = new Page(bigintDictionaryBlock, bigintBigDictionaryBlock);
    assertGroupByHashWork(highCardinalityDictionaryPage, ImmutableList.of(BIGINT, VARCHAR), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
    // Cardinality above Short.MAX_VALUE
    Page lowCardinalityHugeDictionaryPage = new Page(bigintSingletonDictionaryBlock, bigintHugeDictionaryBlock);
    assertGroupByHashWork(lowCardinalityHugeDictionaryPage, ImmutableList.of(BIGINT, BIGINT), MultiChannelGroupByHash.GetNonDictionaryGroupIdsWork.class);
}
Also used : 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) VariableWidthBlock(io.trino.spi.block.VariableWidthBlock) Test(org.testng.annotations.Test)

Example 2 with BlockAssertions.createLongsBlock

use of io.trino.block.BlockAssertions.createLongsBlock 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 BlockAssertions.createLongsBlock

use of io.trino.block.BlockAssertions.createLongsBlock 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 4 with BlockAssertions.createLongsBlock

use of io.trino.block.BlockAssertions.createLongsBlock in project trino by trinodb.

the class TestGroupByHash method testAddPage.

@Test
public void testAddPage() {
    GroupByHash groupByHash = createGroupByHash(TEST_SESSION, ImmutableList.of(BIGINT), new int[] { 0 }, Optional.of(1), 100, JOIN_COMPILER, TYPE_OPERATOR_FACTORY, NOOP);
    for (int tries = 0; tries < 2; tries++) {
        for (int value = 0; value < MAX_GROUP_ID; value++) {
            Block block = BlockAssertions.createLongsBlock(value);
            Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
            Page page = new Page(block, hashBlock);
            for (int addValuesTries = 0; addValuesTries < 10; addValuesTries++) {
                groupByHash.addPage(page).process();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // add the page again using get group ids and make sure the group count didn't change
                Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
                work.process();
                GroupByIdBlock groupIds = work.getResult();
                assertEquals(groupByHash.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                assertEquals(groupIds.getGroupCount(), tries == 0 ? value + 1 : MAX_GROUP_ID);
                // verify the first position
                assertEquals(groupIds.getPositionCount(), 1);
                long groupId = groupIds.getGroupId(0);
                assertEquals(groupId, value);
            }
        }
    }
}
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 5 with BlockAssertions.createLongsBlock

use of io.trino.block.BlockAssertions.createLongsBlock in project trino by trinodb.

the class TestGroupByHash method testDictionaryBigintGroupByHash.

@Test
public void testDictionaryBigintGroupByHash() {
    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, 1L);
    Block hashBlock = TypeTestUtils.getHashBlock(ImmutableList.of(BIGINT), block);
    int[] ids = new int[] { 0, 0, 1, 1 };
    Page page = new Page(new DictionaryBlock(block, ids), new DictionaryBlock(hashBlock, ids));
    groupByHash.addPage(page).process();
    assertEquals(groupByHash.getGroupCount(), 2);
    Work<GroupByIdBlock> work = groupByHash.getGroupIds(page);
    work.process();
    GroupByIdBlock groupIds = work.getResult();
    assertEquals(groupIds.getGroupCount(), 2);
    assertEquals(groupIds.getPositionCount(), 4);
    assertEquals(groupIds.getGroupId(0), 0);
    assertEquals(groupIds.getGroupId(1), 0);
    assertEquals(groupIds.getGroupId(2), 1);
    assertEquals(groupIds.getGroupId(3), 1);
}
Also used : GroupByHash.createGroupByHash(io.trino.operator.GroupByHash.createGroupByHash) DictionaryBlock(io.trino.spi.block.DictionaryBlock) 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)6 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)6 BlockAssertions.createStringSequenceBlock (io.trino.block.BlockAssertions.createStringSequenceBlock)6 Page (io.trino.spi.Page)6 Block (io.trino.spi.block.Block)6 DictionaryBlock (io.trino.spi.block.DictionaryBlock)6 RunLengthEncodedBlock (io.trino.spi.block.RunLengthEncodedBlock)6 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)6 TypeTestUtils.getHashBlock (io.trino.type.TypeTestUtils.getHashBlock)6 Test (org.testng.annotations.Test)6 GroupByHash.createGroupByHash (io.trino.operator.GroupByHash.createGroupByHash)5 PageBuilder (io.trino.spi.PageBuilder)1 ArrayList (java.util.ArrayList)1