Search in sources :

Example 1 with MapBlock

use of io.trino.spi.block.MapBlock in project trino by trinodb.

the class TestMapBlock method testLazyMiddleGetRegionHashTable.

private void testLazyMiddleGetRegionHashTable(Map<String, Long>[] testValues) {
    MapBlock block = createBlockWithValuesFromKeyValueBlock(testValues);
    BlockBuilder blockBuilder = createBlockBuilderWithValues(testValues);
    MapBlock midSection = (MapBlock) block.getRegion(2, 4);
    assertFalse(block.isHashTablesPresent());
    assertFalse(midSection.isHashTablesPresent());
    assertBlock(midSection, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 2, 6));
    assertTrue(block.isHashTablesPresent());
    assertTrue(midSection.isHashTablesPresent());
    MapBlock prefix = (MapBlock) block.getRegion(0, 4);
    assertTrue(prefix.isHashTablesPresent());
    assertBlock(prefix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 0, 4));
    MapBlock suffix = (MapBlock) block.getRegion(4, 4);
    assertTrue(suffix.isHashTablesPresent());
    assertBlock(suffix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 4, 8));
}
Also used : MapBlock(io.trino.spi.block.MapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapBlockBuilder(io.trino.spi.block.MapBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 2 with MapBlock

use of io.trino.spi.block.MapBlock in project trino by trinodb.

the class TestMapBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    Block emptyBlock = new ByteArrayBlock(0, Optional.empty(), new byte[0]);
    Block compactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
    Block compactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(16).getBytes());
    Block inCompactKeyBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
    Block inCompactValueBlock = new ByteArrayBlock(16, Optional.empty(), createExpectedValue(17).getBytes());
    int[] offsets = { 0, 1, 1, 2, 4, 8, 16 };
    boolean[] mapIsNull = { false, true, false, false, false, false };
    testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.empty(), new int[1], emptyBlock, emptyBlock));
    testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.of(mapIsNull), offsets, compactKeyBlock, compactValueBlock));
    // TODO: Add test case for a sliced MapBlock
    // underlying key/value block is not compact
    testIncompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(Optional.of(mapIsNull), offsets, inCompactKeyBlock, inCompactValueBlock));
}
Also used : MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) Test(org.testng.annotations.Test)

Example 3 with MapBlock

use of io.trino.spi.block.MapBlock in project trino by trinodb.

the class TestMapBlock method testLazyGetPositionsHashTable.

private void testLazyGetPositionsHashTable(Map<String, Long>[] testValues) {
    MapBlock block = createBlockWithValuesFromKeyValueBlock(testValues);
    assertFalse(block.isHashTablesPresent());
    BlockBuilder blockBuilder = createBlockBuilderWithValues(testValues);
    int[] testPositions = { 7, 1, 5, 2, 3, 7 };
    Block prefix = block.getPositions(testPositions, 0, testPositions.length);
    assertFalse(block.isHashTablesPresent());
    assertBlock(prefix, () -> blockBuilder.newBlockBuilderLike(null), getArrayPositions(testValues, testPositions));
    assertTrue(block.isHashTablesPresent());
}
Also used : MapBlock(io.trino.spi.block.MapBlock) Block(io.trino.spi.block.Block) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) ByteArrayBlock(io.trino.spi.block.ByteArrayBlock) MapBlock(io.trino.spi.block.MapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapBlockBuilder(io.trino.spi.block.MapBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 4 with MapBlock

use of io.trino.spi.block.MapBlock in project trino by trinodb.

the class TestMapBlock method testLazyBeginningGetRegionHashTable.

private void testLazyBeginningGetRegionHashTable(Map<String, Long>[] testValues) {
    MapBlock block = createBlockWithValuesFromKeyValueBlock(testValues);
    assertFalse(block.isHashTablesPresent());
    BlockBuilder blockBuilder = createBlockBuilderWithValues(testValues);
    MapBlock prefix = (MapBlock) block.getRegion(0, 4);
    assertFalse(block.isHashTablesPresent());
    assertFalse(prefix.isHashTablesPresent());
    assertBlock(prefix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 0, 4));
    assertTrue(block.isHashTablesPresent());
    assertTrue(prefix.isHashTablesPresent());
    MapBlock midSection = (MapBlock) block.getRegion(2, 4);
    assertTrue(midSection.isHashTablesPresent());
    assertBlock(midSection, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 2, 6));
    MapBlock suffix = (MapBlock) block.getRegion(4, 4);
    assertTrue(suffix.isHashTablesPresent());
    assertBlock(suffix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 4, 8));
}
Also used : MapBlock(io.trino.spi.block.MapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapBlockBuilder(io.trino.spi.block.MapBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 5 with MapBlock

use of io.trino.spi.block.MapBlock in project trino by trinodb.

the class TestMapBlock method testLazyEndGetRegionHashTable.

private void testLazyEndGetRegionHashTable(Map<String, Long>[] testValues) {
    MapBlock block = createBlockWithValuesFromKeyValueBlock(testValues);
    BlockBuilder blockBuilder = createBlockBuilderWithValues(testValues);
    MapBlock suffix = (MapBlock) block.getRegion(4, 4);
    assertFalse(block.isHashTablesPresent());
    assertFalse(suffix.isHashTablesPresent());
    assertBlock(suffix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 4, 8));
    assertTrue(block.isHashTablesPresent());
    assertTrue(suffix.isHashTablesPresent());
    MapBlock prefix = (MapBlock) block.getRegion(0, 4);
    assertTrue(prefix.isHashTablesPresent());
    assertBlock(prefix, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 0, 4));
    MapBlock midSection = (MapBlock) block.getRegion(2, 4);
    assertTrue(midSection.isHashTablesPresent());
    assertBlock(midSection, () -> blockBuilder.newBlockBuilderLike(null), Arrays.copyOfRange(testValues, 2, 6));
}
Also used : MapBlock(io.trino.spi.block.MapBlock) SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapBlockBuilder(io.trino.spi.block.MapBlockBuilder) BlockBuilder(io.trino.spi.block.BlockBuilder)

Aggregations

MapBlock (io.trino.spi.block.MapBlock)5 SingleMapBlock (io.trino.spi.block.SingleMapBlock)5 BlockBuilder (io.trino.spi.block.BlockBuilder)4 MapBlockBuilder (io.trino.spi.block.MapBlockBuilder)4 BlockAssertions.createLongsBlock (io.trino.block.BlockAssertions.createLongsBlock)2 BlockAssertions.createStringsBlock (io.trino.block.BlockAssertions.createStringsBlock)2 Block (io.trino.spi.block.Block)2 ByteArrayBlock (io.trino.spi.block.ByteArrayBlock)2 Test (org.testng.annotations.Test)1