public static void writePositionToBlockBuilder(Block block, int position, BlockBuilder blockBuilder)
    {
        if (block instanceof DictionaryBlock) {
            position = ((DictionaryBlock) block).getId(position);
            block = ((DictionaryBlock) block).getDictionary();
        }

        if (blockBuilder instanceof MapBlockBuilder) {
            writePositionToMapBuilder(block, position, (MapBlockBuilder) blockBuilder);
        }
        else if (blockBuilder instanceof ArrayBlockBuilder) {
            writePositionToArrayBuilder(block, position, (ArrayBlockBuilder) blockBuilder);
        }
        else if (blockBuilder instanceof RowBlockBuilder) {
            writePositionToRowBuilder(block, position, (RowBlockBuilder) blockBuilder);
        }
        else {
            block.writePositionTo(position, blockBuilder);
        }
    }
@Test
    public void testMapBlockBuilder()
    {
        BlockBuilder blockBuilder1 = TEST_MAP_TYPE.createBlockBuilder(null, 1);
        BlockBuilder mapBlockBuilder = blockBuilder1.beginBlockEntry();
        writeValuesToMapBuilder(mapBlockBuilder);
        Block expectedBlock = blockBuilder1.closeEntry().build();

        // write values to a new block using BlockBuilderUtil
        BlockBuilder blockBuilder2 = TEST_MAP_TYPE.createBlockBuilder(null, 1);
        writePositionToBlockBuilder(expectedBlock, 0, blockBuilder2);
        Block newBlock = blockBuilder2.build();
        assertEquals(newBlock, expectedBlock);
    }