Roaring bitmap aggregate functions aggregate numeric data into a Roaring bitmap. OceanBase Database supports the following Roaring bitmap aggregate functions: rb_build_agg(), rb_or_agg(), and rb_and_agg().
rb_build_agg
rb_build_agg() aggregates the values of a numeric column into a Roaring bitmap. The syntax is as follows:
rb_build_agg(values)
The values parameter, which is of the UINT64 format, specifies the numeric column for building a Roaring bitmap. 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 is an example:
CREATE TABLE t1(val bigint);
INSERT INTO t1 VALUES(1),(2),(3);
SELECT rb_to_string(rb_build_agg(val)) FROM t1;
+---------------------------------+
| rb_to_string(rb_build_agg(val)) |
+---------------------------------+
| 1,2,3 |
+---------------------------------+
1 row in set
rb_or_agg
rb_or_agg() performs an OR operation on multiple rows of data in a Roaring bitmap column and aggregates the resulting data into a Roaring bitmap. The syntax is as follows:
rb_or_agg(rb_in)
rb_in specifies the Roaring bitmap column for aggregation.
Here is an example:
CREATE TABLE t2(rb roaringbitmap);
INSERT INTO t2 VALUES (rb_from_string('1,2,3')),(rb_from_string('2,3,4'));
SELECT rb_to_string(rb_or_agg(rb)) FROM t2;
+-----------------------------+
| rb_to_string(rb_or_agg(rb)) |
+-----------------------------+
| 1,2,3,4 |
+-----------------------------+
1 row in set
rb_and_agg
rb_and_agg() performs an AND operation on multiple rows of data in a Roaring bitmap column and aggregates the resulting data into a Roaring bitmap. The syntax is as follows:
rb_and_agg(rb_in)
rb_in specifies the Roaring bitmap column for aggregation.
Here is an example:
SELECT rb_to_string(rb_and_agg(rb)) FROM t2;
+------------------------------+
| rb_to_string(rb_and_agg(rb)) |
+------------------------------+
| 2,3 |
+------------------------------+
1 row in set