A Roaring bitmap constructor function constructs a Roaring bitmap object. OceanBase Database supports the following Roaring bitmap constructor functions: rb_build_empty(), rb_build_varbinary(), and rb_from_string().
Note
To return query results in the hexadecimal format, see Create Roaring bitmap columns.
rb_build_empty
The rb_build_empty() function constructs an empty Roaring bitmap object. The syntax is as follows:
rb_build_empty()
This function requires no input arguments.
Here are several examples:
SELECT rb_build_empty();
+------------------------------------+
| rb_build_empty() |
+------------------------------------+
| 0x0100 |
+------------------------------------+
1 row in set
SELECT rb_is_empty(rb_build_empty());
+-------------------------------+
| rb_is_empty(rb_build_empty()) |
+-------------------------------+
| 1 |
+-------------------------------+
1 row in set
rb_build_varbinary
The rb_build_varbinary() function constructs a Roaring bitmap object of the VARBINARY data type. VARBINARY is a proprietary format of OceanBase Database. A VARBINARY string consists of the version, type, and data. The syntax is as follows:
rb_build_varbinary(bin_str)
The input argument is a VARBINARY string.
Here are several examples:
SELECT rb_to_string(rb_build_varbinary(x'0100'));
+-------------------------------------------+
| rb_to_string(rb_build_varbinary(x'0100')) |
+-------------------------------------------+
| |
+-------------------------------------------+
1 row in set
SELECT rb_to_string(rb_build_varbinary(x'0103020100000002000000'));
+-------------------------------------------------------------+
| rb_to_string(rb_build_varbinary(x'0103020100000002000000')) |
+-------------------------------------------------------------+
| 1,2 |
+-------------------------------------------------------------+
1 row in set
rb_from_string
The rb_from_string() function constructs a Roaring bitmap object based on a string of a specific format. The string consists of elements required to construct the Roaring bitmap object. The elements are separated with commas (,), for example, 1,2,3,4. The syntax is as follows:
rb_from_string(str)
The input string can be of the INT32 or INT64 format. OceanBase Database supports the value range of [0, UINT64_MAX]. To ensure compatibility with PostgreSQL, OceanBase Database also supports negative integers within the range of [INT32_MIN,0). If a negative integer is input, the function converts the negative integer into a UINT32 value. For example, if -1 is input, the function returns 4294967295.
Here are several examples:
SELECT rb_from_string('1,2,3');
+--------------------------------------------------+
| rb_from_string('1,2,3') |
+--------------------------------------------------+
| 0x010303010000000200000003000000 |
+--------------------------------------------------+
1 row in set
SELECT rb_to_string(rb_from_string('-1'));
+------------------------------------+
| rb_to_string(rb_from_string('-1')) |
+------------------------------------+
| 4294967295 |
+------------------------------------+
1 row in set