use of com.facebook.presto.common.block.MapBlock in project presto by prestodb.
the class TestMapBlockBuilder method testMapBlockBuilderWithNullKeys.
@Test
public void testMapBlockBuilderWithNullKeys() {
MapBlockBuilder blockBuilder = createMapBlockBuilder();
for (int i = 0; i < MAP_POSITIONS; i++) {
if (i % 10 == 0) {
// Map is null
blockBuilder.appendNull();
} else {
// Map is valid.
BlockBuilder entryBuilder = blockBuilder.beginBlockEntry();
for (int j = 0; j < i; j++) {
if (j == 5) {
// Null Keys
entryBuilder.appendNull();
} else {
BIGINT.writeLong(entryBuilder, j);
}
BIGINT.writeLong(entryBuilder, i);
}
blockBuilder.closeEntry();
}
assertFalse(blockBuilder.isHashTablesPresent());
}
// Verify the contents of the map.
MapBlock mapBlock = (MapBlock) blockBuilder.build();
assertFalse(mapBlock.isHashTablesPresent());
ColumnarMap columnarMap = ColumnarMap.toColumnarMap(mapBlock);
for (int i = 0; i < MAP_POSITIONS; i++) {
assertEquals(columnarMap.isNull(i), i % 10 == 0);
Block keysBlock = columnarMap.getKeysBlock();
Block valuesBlock = columnarMap.getValuesBlock();
if (!columnarMap.isNull(i)) {
int offset = columnarMap.getOffset(i);
for (int j = 0; j < i; j++) {
assertEquals(keysBlock.isNull(offset + j), j == 5);
if (!keysBlock.isNull(offset + j)) {
assertEquals(BIGINT.getLong(keysBlock, offset + j), j);
}
assertEquals(BIGINT.getLong(valuesBlock, offset + j), i);
}
}
}
// Verify block and newBlockBuilder does not have the hashTables present.
assertFalse(mapBlock.isHashTablesPresent());
MapBlockBuilder anotherBuilder = (MapBlockBuilder) blockBuilder.newBlockBuilderLike(null);
assertFalse(anotherBuilder.isHashTablesPresent());
}
use of com.facebook.presto.common.block.MapBlock in project presto by prestodb.
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(0, Optional.empty(), new int[1], emptyBlock, emptyBlock));
testCompactBlock(mapType(TINYINT, TINYINT).createBlockFromKeyValue(mapIsNull.length, 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(mapIsNull.length, Optional.of(mapIsNull), offsets, inCompactKeyBlock, inCompactValueBlock));
}
Aggregations