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));
}
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));
}
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());
}
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));
}
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));
}
Aggregations