Search in sources :

Example 6 with ColumnarMap

use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.

the class MapColumnWriter method writeBlock.

@Override
public void writeBlock(ColumnChunk columnChunk) throws IOException {
    ColumnarMap columnarMap = ColumnarMap.toColumnarMap(columnChunk.getBlock());
    ImmutableList<DefinitionLevelIterable> defLevelIterables = ImmutableList.<DefinitionLevelIterable>builder().addAll(columnChunk.getDefinitionLevelIterables()).add(DefinitionLevelIterables.of(columnarMap, maxDefinitionLevel)).build();
    ImmutableList<RepetitionLevelIterable> repLevelIterables = ImmutableList.<RepetitionLevelIterable>builder().addAll(columnChunk.getRepetitionLevelIterables()).add(RepetitionLevelIterables.of(columnarMap, maxRepetitionLevel)).build();
    keyWriter.writeBlock(new ColumnChunk(columnarMap.getKeysBlock(), defLevelIterables, repLevelIterables));
    valueWriter.writeBlock(new ColumnChunk(columnarMap.getValuesBlock(), defLevelIterables, repLevelIterables));
}
Also used : RepetitionLevelIterable(com.facebook.presto.parquet.writer.levels.RepetitionLevelIterable) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) DefinitionLevelIterable(com.facebook.presto.parquet.writer.levels.DefinitionLevelIterable)

Example 7 with ColumnarMap

use of com.facebook.presto.common.block.ColumnarMap 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());
}
Also used : MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) AbstractMapBlock(com.facebook.presto.common.block.AbstractMapBlock) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) MapBlock(com.facebook.presto.common.block.MapBlock) Block(com.facebook.presto.common.block.Block) AbstractMapBlock(com.facebook.presto.common.block.AbstractMapBlock) SingleMapBlock(com.facebook.presto.common.block.SingleMapBlock) MapBlock(com.facebook.presto.common.block.MapBlock) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) MapBlockBuilder(com.facebook.presto.common.block.MapBlockBuilder) Test(org.testng.annotations.Test)

Example 8 with ColumnarMap

use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.

the class TestOrcMapNullKey method readMap.

private static Map<Long, Long> readMap(Block block, int rowId) {
    ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
    assertFalse(columnarMap.isNull(rowId));
    Block keysBlock = columnarMap.getKeysBlock();
    Block valuesBlock = columnarMap.getValuesBlock();
    Map<Long, Long> actual = new HashMap<>();
    for (int i = 0; i < columnarMap.getEntryCount(rowId); i++) {
        int position = columnarMap.getOffset(rowId) + i;
        Long key = keysBlock.isNull(position) ? null : BIGINT.getLong(keysBlock, position);
        Long value = valuesBlock.isNull(position) ? null : BIGINT.getLong(valuesBlock, position);
        actual.put(key, value);
    }
    return actual;
}
Also used : HashMap(java.util.HashMap) ColumnarMap(com.facebook.presto.common.block.ColumnarMap) Block(com.facebook.presto.common.block.Block)

Example 9 with ColumnarMap

use of com.facebook.presto.common.block.ColumnarMap in project presto by prestodb.

the class TestUnnesterUtil method buildExpectedUnnestedMapBlocks.

private static Block[] buildExpectedUnnestedMapBlocks(Block block, Type keyType, Type valueType, int[] maxCardinalities, int totalEntries) {
    ColumnarMap columnarMap = ColumnarMap.toColumnarMap(block);
    Block keyBlock = columnarMap.getKeysBlock();
    Block valuesBlock = columnarMap.getValuesBlock();
    BlockBuilder keyBlockBuilder = keyType.createBlockBuilder(null, totalEntries);
    BlockBuilder valueBlockBuilder = valueType.createBlockBuilder(null, totalEntries);
    int positionCount = block.getPositionCount();
    int blockPosition = 0;
    for (int i = 0; i < positionCount; i++) {
        int cardinality = columnarMap.getEntryCount(i);
        for (int j = 0; j < cardinality; j++) {
            keyType.appendTo(keyBlock, blockPosition, keyBlockBuilder);
            valueType.appendTo(valuesBlock, blockPosition, valueBlockBuilder);
            blockPosition++;
        }
        int maxCardinality = maxCardinalities[i];
        for (int j = cardinality; j < maxCardinality; j++) {
            keyBlockBuilder.appendNull();
            valueBlockBuilder.appendNull();
        }
    }
    Block[] blocks = new Block[2];
    blocks[0] = keyBlockBuilder.build();
    blocks[1] = valueBlockBuilder.build();
    return blocks;
}
Also used : ColumnarMap(com.facebook.presto.common.block.ColumnarMap) Block(com.facebook.presto.common.block.Block) BlockBuilder(com.facebook.presto.common.block.BlockBuilder)

Aggregations

ColumnarMap (com.facebook.presto.common.block.ColumnarMap)9 Block (com.facebook.presto.common.block.Block)6 ColumnarMap.toColumnarMap (com.facebook.presto.common.block.ColumnarMap.toColumnarMap)3 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)2 ColumnarArray (com.facebook.presto.common.block.ColumnarArray)2 DictionaryBlock (com.facebook.presto.common.block.DictionaryBlock)2 MapBlock (com.facebook.presto.common.block.MapBlock)2 MapBlockBuilder (com.facebook.presto.common.block.MapBlockBuilder)2 RunLengthEncodedBlock (com.facebook.presto.common.block.RunLengthEncodedBlock)2 Slice (io.airlift.slice.Slice)2 Test (org.testng.annotations.Test)2 ColumnarTestUtils.assertBlock (com.facebook.presto.block.ColumnarTestUtils.assertBlock)1 ColumnarTestUtils.createTestDictionaryBlock (com.facebook.presto.block.ColumnarTestUtils.createTestDictionaryBlock)1 ColumnarTestUtils.createTestRleBlock (com.facebook.presto.block.ColumnarTestUtils.createTestRleBlock)1 AbstractMapBlock (com.facebook.presto.common.block.AbstractMapBlock)1 ArrayBlock (com.facebook.presto.common.block.ArrayBlock)1 BlockLease (com.facebook.presto.common.block.BlockLease)1 ColumnarRow (com.facebook.presto.common.block.ColumnarRow)1 RowBlock (com.facebook.presto.common.block.RowBlock)1 SingleMapBlock (com.facebook.presto.common.block.SingleMapBlock)1