Search in sources :

Example 1 with SingleMapBlockWriter

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);
        }
    }
}
Also used : MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) Slice(io.airlift.slice.Slice) SingleMapBlockWriter(com.facebook.presto.common.block.SingleMapBlockWriter) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) ColumnarMap.toColumnarMap(com.facebook.presto.common.block.ColumnarMap.toColumnarMap) Test(org.testng.annotations.Test)

Aggregations

ColumnarMap (com.facebook.presto.common.block.ColumnarMap)1 ColumnarMap.toColumnarMap (com.facebook.presto.common.block.ColumnarMap.toColumnarMap)1 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)1 SingleMapBlockWriter (com.facebook.presto.common.block.SingleMapBlockWriter)1 Slice (io.airlift.slice.Slice)1 Test (org.testng.annotations.Test)1