use of com.facebook.presto.common.block.SingleMapBlockWriter in project presto by prestodb.
the class TestColumnarMap method testMapWithNullKeys.
@Test
public void testMapWithNullKeys() {
// Presto Query Engine does not support Map with Null keys.
// Presto ORC reader and Writer are used as library in some other
// projects and it requires null keys to be supported in the Map.
MapBlockBuilder mapBlockBuilder = createMapBuilder(100);
mapBlockBuilder.appendNull();
for (int i = 1; i < 100; i++) {
Slice valueSlice = Slices.utf8Slice(Integer.toString(i));
SingleMapBlockWriter blockWriter = mapBlockBuilder.beginBlockEntry();
// Null Key
blockWriter.appendNull();
VARCHAR.writeSlice(blockWriter, valueSlice);
for (int j = 1; j < i; j++) {
Slice keySlice = Slices.utf8Slice(Integer.toString(j));
VARCHAR.writeSlice(blockWriter, keySlice);
VARCHAR.writeSlice(blockWriter, valueSlice);
}
mapBlockBuilder.closeEntry();
}
ColumnarMap columnarMap = toColumnarMap(mapBlockBuilder.build());
assertEquals(columnarMap.getPositionCount(), 100);
assertTrue(columnarMap.isNull(0));
for (int i = 1; i < 100; i++) {
assertFalse(columnarMap.isNull(i));
Slice valueSlice = Slices.utf8Slice(Integer.toString(i));
int offset = columnarMap.getOffset(i);
assertTrue(columnarMap.getKeysBlock().isNull(offset));
verifySlice(columnarMap.getValuesBlock(), offset, valueSlice);
for (int j = 1; j < i; j++) {
Slice keySlice = Slices.utf8Slice(Integer.toString(j));
verifySlice(columnarMap.getKeysBlock(), offset + j, keySlice);
verifySlice(columnarMap.getValuesBlock(), offset + j, valueSlice);
}
}
}
Aggregations