> ## Documentation Index
> Fetch the complete documentation index at: /documents/llms.txt
> Use this file to discover all available pages before exploring further.

# base64_to_bitmap

> Before you import bitmap data into the database, you need to serialize the data and encode the data as a Base64 string.

Before you import bitmap data into the database, you need to serialize the data and encode the data as a Base64 string. When you import the Base64 string into the database, you need to convert the string into bitmap data.
This function is used to convert Base64 strings into bitmap data.

This function is supported from v2.3.

## Syntax

```Haskell theme={null}
BITMAP base64_to_bitmap(VARCHAR bitmap)
```

## Parameters

`bitmap`: The supported data type is VARCHAR. Before you load Bitmap data into the database, you can use Java or C++ to [create a BitmapValue object](https://github.com/StarRocks/starrocks/blob/main/fe/plugin-common/src/test/java/com/starrocks/types/BitmapValueTest.java), add an element, serialize the data, and encode the data as a Base64 string. Then, pass the Base64 string as an input parameter into this function.

## Return value

Returns a value of the BITMAP type.

## Examples

Create a database named `bitmapdb` and a table named `bitmap`. Use Stream Load to import JSON data into `bitmap_table`. During this process, use base64\_to\_bitmap to convert the Base64 string in the JSON file into bitmap data.

1. Create a database and a table in the database. In this example, a Primary Key table is created.

   ```SQL theme={null}
   CREATE database bitmapdb;
   USE bitmapdb;
   CREATE TABLE `bitmap_table` (
   `tagname` varchar(65533) NOT NULL COMMENT "Tag name",
   `tagvalue` varchar(65533) NOT NULL COMMENT "Tag value",
   `userid` bitmap NOT NULL COMMENT "User ID"
   ) ENGINE=OLAP
   PRIMARY KEY(`tagname`, `tagvalue`)
   COMMENT "OLAP"
   DISTRIBUTED BY HASH(`tagname`)
   PROPERTIES (
   "replication_num" = "3",
   "storage_format" = "DEFAULT"
   );
   ```

2. Use [Stream Load](/documents/4.2/sql-reference/sql-statements/loading_unloading/STREAM_LOAD.md) to import JSON data into `bitmap_table`.

   Suppose there is a JSON file named **simpledata**. This file has the following content and `userid` is a Base64-encoded string.

   ```JSON theme={null}
   {
       "tagname": "Product", "tagvalue": "Insurance", "userid":"AjowAAABAAAAAAACABAAAAABAAIAAwA="
   }
   ```

   Use base64\_to\_bitmap to convert  `userid` into a bitmap value.

   ```Plain theme={null}
   curl --location-trusted -u <username>:<password>\
       -H "columns: c1,c2,c3,tagname=c1,tagvalue=c2,userid=base64_to_bitmap(c3)"\
       -H "label:bitmap123"\
       -H "format: json"\
       -H "jsonpaths: [\"$.tagname\",\"$.tagvalue\",\"$.userid\"]"\
       -T simpleData http://host:port/api/bitmapdb/bitmap_table/_stream_load
   ```

3. Query data from `bitmap_table`.

   ```Plaintext theme={null}
   mysql> select tagname,tagvalue,bitmap_to_string(userid) from bitmap_table;
   +--------------+----------+----------------------------+
   | tagname      | tagvalue | bitmap_to_string(`userid`) |
   +--------------+----------+----------------------------+
   | Product      | Insurance      | 1,2,3                |
   +--------------+----------+----------------------------+
   1 rows in set (0.01 sec)
   ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.