RoaringBitmap is an efficient bitmap compression algorithm that is widely used in various programming languages and big data platforms. RoaringBitmap is suitable for computing ultra-high dimensional data and is commonly used in computing scenarios such as deduplication, tag filtering, and time series data processing. This topic describes the roaring bitmap functions supported by MaxCompute.
Basic principles
The following content describes how 32-bit integers and 64-bit integers are stored by using the RoaringBitmap algorithm:
Up to 216 containers can be created to store 32-bit integers. Each 32-bit integer contains 16 most significant bits and 16 least significant bits. The 16 most significant bits of a 32-bit integer are used to determine the container number, and the 16 least significant bits of the 32-bit integer are stored in the container that corresponds to the container number.
Up to 232 containers can be created to store 64-bit integers. Each 64-bit integer contains 32 most significant bits and 32 least significant bits. The 32 most significant bits of a 64-bit integer are used to determine the container to store the 32 least significant bits of the 64-bit integer in the first-level index.
Array containers, bitmap containers, and run containers are supported.
RoaringBitmap32 and RoaringBitmap64 are implemented for 32-bit integers and 64-bit integers respectively within the algorithm. However, you do not need to distinguish between RoaringBitmap32 and RoaringBitmap64 when you use them.
Roaring bitmaps can use this storage structure to rapidly retrieve specific values. Roaring bitmaps support efficient bitwise operations such as AND, OR, and XOR between containers. Therefore, roaring bitmaps can deliver excellent storage and computing performance.
Limits
If you use a function whose parameters or return values contain roaring bitmap data, you must specify
set odps.sql.type.system.odps2=true;. Otherwise, an error that is similar toSemantic analysis exception - function or view xxx cannot be resolvedis reported during execution.You cannot create a table that contains columns of the RoaringBitmap type. Instead, you can serialize RoaringBitmap data by using the
RB_SERIALIZEfunction and store it as a binary type. When you need to use this data, you can deserialize the binary type back into a RoaringBitmap by using theRB_DESERIALIZEfunction.Roaring bitmap data cannot be displayed in the execution result. Therefore, all functions whose output type is RoaringBitmap will fail to be executed. In this case, you can use the
RB_TO_ARRAYfunction to convert the roaring bitmap data into an integer array, which is used as the output. For example, the returned result of theSELECT rb_to_array(rb_build(array(1, 2, 2)));statement is[1, 2].
Aggregate functions
The following table describes the roaring bitmap aggregate functions supported by MaxCompute.
Function | Description |
Converts values of an integer type into the RoaringBitmap type. | |
Constructs a roaring bitmap to calculate the cardinality of integer columns. | |
Calculates the intersection of RoaringBitmap columns, which indicates the elements that exist in all RoaringBitmap columns. | |
Calculates the union of RoaringBitmap columns, which indicates all elements in all RoaringBitmap columns. | |
Performs an XOR operation on all data in RoaringBitmap columns. This function is used to obtain the elements that appear only once in RoaringBitmap columns. | |
Calculates the cardinality of the intersection of RoaringBitmap columns. | |
Calculates the cardinality of the union of RoaringBitmap columns. | |
Calculates the cardinality of the result of the XOR operation on RoaringBitmap columns. |
Sample code
The following sample aggregate functions are implemented based on sample data in the t_test table. The following sample code provides an example on how to create the t_test table and insert data into the table.
DROP TABLE IF EXISTS t_test;
CREATE TABLE t_test
(
col_int INT
,col_bigint BIGINT
);
INSERT INTO t_test VALUES(1,1),(2,2),(1,2);RB_BUILD_AGG
Syntax
roaringbitmap rb_build_agg(int|bigint col)Description
Converts values of an integer type into the RoaringBitmap type.
Parameters
col: required. It is an attribute column of the INT or BIGINT type.
Return value
A roaring bitmap that contains all data of the col column is returned. The return value varies based on the following rules:
If the col column is of the INT type, data of the RoaringBitmap32 type is returned.
If the col column is of the BIGINT type, data of the RoaringBitmap64 type is returned.
Examples
Example 1: Query data of the RoaringBitmap32 type.
SELECT rb_to_array(rb_build_agg(col_int)) from t_test;Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+Example 2: Query data of the RoaringBitmap64 type.
SELECT rb_to_array(rb_build_agg(col_bigint)) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+
RB_CARDINALITY_AGG
Syntax
bigint rb_cardinality_agg(int|bigint col)Description
Calculates the cardinality of integer columns by constructing a roaring bitmap, which is equivalent to
count(distinct).Parameters
col: required. It is an attribute column of the INT or BIGINT type.
Return value
The cardinality of integer columns is returned. The type of the return value is BIGINT.
Examples
Example 1: Query the cardinality of the
col_intcolumn.SELECT rb_cardinality_agg(col_int) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+Example 2: Query the cardinality of the
col_bigintcolumn.SELECT rb_cardinality_agg(col_bigint) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+
RB_AND_AGG
Syntax
roaringbitmap rb_and_agg(roaringbitmap col)Description
Calculates the intersection of RoaringBitmap columns, which indicates the elements that exist in all RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The intersection of RoaringBitmap columns is returned. The type of the return value is RoaringBitmap.
Examples
Example 1
SELECT rb_to_array(rb_and_agg(rb_build(array(col_int)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [] | +------------+Example 2
SELECT rb_to_array(rb_and_agg(rb_build(array(col_bigint)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [] | +------------+
RB_OR_AGG
Syntax
roaringbitmap rb_or_agg(roaringbitmap col)Description
Calculates the union of RoaringBitmap columns, which indicates all elements in all RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The union of RoaringBitmap columns is returned. The type of the return value is RoaringBitmap.
Examples
Example 1
SELECT rb_to_array(rb_or_agg(rb_build(array(col_int)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+Example 2
SELECT rb_to_array(rb_or_agg(rb_build(array(col_bigint)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+
RB_XOR_AGG
Syntax
roaringbitmap rb_xor_agg(roaringbitmap col)Description
Performs an XOR operation on all data in RoaringBitmap columns. This function is used to obtain the elements that appear only once in RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The result of the XOR operation on RoaringBitmap columns is returned. The type of the return value is RoaringBitmap.
Examples
Example 1
SELECT rb_to_array(rb_xor_agg(rb_build(array(col_int)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [2] | +------------+Example 2
SELECT rb_to_array(rb_xor_agg(rb_build(array(col_bigint)))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | [1] | +------------+
RB_AND_CARDINALITY_AGG
Syntax
bigint rb_and_cardinality_agg(roaringbitmap col)Description
Calculates the cardinality of the intersection of all roaring bitmaps in RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The cardinality of the intersection of RoaringBitmap columns is returned. The type of the return value is BIGINT.
Examples
Example 1
SELECT rb_and_cardinality_agg(rb_build(array(col_int))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 0 | +------------+Example 2
SELECT rb_and_cardinality_agg(rb_build(array(col_bigint))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 0 | +------------+
RB_OR_CARDINALITY_AGG
Syntax
bigint rb_or_cardinality_agg(roaringbitmap col)Description
Calculates the cardinality of the union of all roaring bitmaps in RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The cardinality of the union of RoaringBitmap columns is returned. The type of the return value is BIGINT.
Examples
Example 1
SELECT rb_or_cardinality_agg(rb_build(array(col_int))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+Example 2
SELECT rb_or_cardinality_agg(rb_build(array(col_bigint))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+
RB_XOR_CARDINALITY_AGG
Syntax
bigint rb_xor_cardinality_agg(roaringbitmap col)Description
Calculates the cardinality of the result of the XOR operation on all roaring bitmaps in RoaringBitmap columns.
Parameters
col: required. It is an attribute column of the RoaringBitmap type.
Return value
The cardinality of the result of the XOR operation on RoaringBitmap columns is returned. The type of the return value is BIGINT.
Examples
Example 1
SELECT rb_xor_cardinality_agg(rb_build(array(col_int))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+Example 2
SELECT rb_xor_cardinality_agg(rb_build(array(col_bigint))) FROM t_test;Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+
Functions
The following table describes the roaring bitmap non-aggregate functions supported by MaxCompute.
Function | Description |
Converts an integer array into a roaring bitmap. | |
Converts a roaring bitmap into an integer array and sorts elements in the array in ascending order. | |
Calculates the cardinality of a roaring bitmap. | |
Calculates the intersection of two roaring bitmaps. Note You can also use the | |
Calculates the union of two roaring bitmaps. Note You can also use the | |
Calculates the result of the XOR operation on two roaring bitmaps. Note You can also use the | |
Calculates the complement of two roaring bitmaps. Note You can also use the | |
Calculates the cardinality of the intersection of two roaring bitmaps. Note You can also use the | |
Calculates the cardinality of the union of two roaring bitmaps. Note You can also use the | |
Calculates the cardinality of the result of the XOR operation on two roaring bitmaps. Note You can also use the | |
Calculates the cardinality of the complement of two roaring bitmaps. Note You can also use the | |
Determines whether two roaring bitmaps are equal. | |
Determines whether two roaring bitmaps are not equal. | |
Determines whether the first roaring bitmap contains the second roaring bitmap. | |
Determines whether two roaring bitmaps intersect. | |
Determines whether a roaring bitmap is empty. | |
Obtains the maximum value in a roaring bitmap. | |
Obtains the minimum value in a roaring bitmap. | |
Obtains a new collection of roaring bitmaps in the | |
Obtains the cardinality of the new collection of roaring bitmaps in the | |
Obtains a new collection of roaring bitmaps after integers in the | |
Obtains a new collection of roaring bitmaps after integers in the | |
Serializes values of the RoaringBitmap type into the BINARY type. | |
Deserializes values of the BINARY type into the RoaringBitmap64 type. | |
Deserializes values of the BINARY type into the RoaringBitmap32 type. |
RB_BUILD
Syntax
roaringbitmap rb_build(array<int|bigint> a)Description
Converts an integer array into a roaring bitmap.
Parameters
a: required. An array in which the elements can be of the INT or BIGINT type. The array cannot be empty.
Return value
A roaring bitmap that contains all data in an array is returned. The return value varies based on the following rules:
If a is of the ARRAY<INT> type, data of the RoaringBitmap32 type is returned.
If a is of the ARRAY<BIGINT> type, data of the RoaringBitmap64 type is returned.
Examples
Example 1: Construct data of the RoaringBitmap32 type.
SELECT rb_to_array(rb_build(array(1, 2, 2)));Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+Example 2: Construct data of the RoaringBitmap64 type.
SELECT rb_to_array(rb_build(array(1L, 2L, 2L)));Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+
RB_TO_ARRAY
Syntax
array<int|bigint> rb_to_array(roaringbitmap a)Description
Converts a roaring bitmap into an integer array and sorts elements in the array in ascending order.
Parameters
a: required.
Return value
An integer array that contains all elements of a roaring bitmap is returned. The return value varies based on the following rules:
If a is of the RoaringBitmap32 type, data of the ARRAY<INT> type is returned.
If a is of the RoaringBitmap64 type, data of the ARRAY<BIGINT> type is returned.
Examples
SELECT rb_to_array(rb_build(array(1, 2, 2)));Returned result:
+------------+ | _c0 | +------------+ | [1,2] | +------------+
RB_CARDINALITY
Syntax
bigint rb_cardinality(roaringbitmap a)Description
Calculates the cardinality of a roaring bitmap.
Parameters
a: required.
Return value
The cardinality of data of the RoaringBitmap type is returned. The type of the return value is BIGINT.
Examples
Example 1
SELECT rb_cardinality(rb_build(array(1, 2, 2)));Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+Example 2
-- 3 is returned. SELECT rb_cardinality(rb_build(array(1L, 2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | 3 | +------------+
RB_AND
Syntax
roaringbitmap rb_and(roaringbitmap a, roaringbitmap b)Description
Calculates the intersection of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The intersection of two roaring bitmaps is returned. The type of the return value is RoaringBitmap. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_and_null2emptyfunction converts the parameter that is NULL into an empty set.Examples
SELECT rb_to_array(rb_and(rb_build(array(1, 2)), rb_build(array(2, 3))));Returned result:
+------------+ | _c0 | +------------+ | [2] | +------------+
RB_OR
Syntax
roaringbitmap rb_or(roaringbitmap a, roaringbitmap b)Description
Calculates the union of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The union of two roaring bitmaps is returned. The type of the return value is RoaringBitmap. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_or_null2emptyfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_to_array(rb_or(rb_build(array(1, 2)), rb_build(array(2, 3))));Returned result:
+------------+ | _c0 | +------------+ | [1,2,3] | +------------+Example 2
-- [1,2,3] is returned. SELECT rb_to_array(rb_or(rb_build(array(1L, 2L)), rb_build(array(2L, 3L))));Returned result:
+------------+ | _c0 | +------------+ | [1,2,3] | +------------+
RB_XOR
Syntax
roaringbitmap rb_xor(roaringbitmap a, roaringbitmap b)Description
Calculates the result of the XOR operation on two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The result of the XOR operation on two roaring bitmaps is returned. The type of the return value is RoaringBitmap. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_xor_null2emptyfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_to_array(rb_xor(rb_build(array(1, 2)), rb_build(array(2, 3))));Returned result:
+------------+ | _c0 | +------------+ | [1,3] | +------------+Example 2
SELECT rb_to_array(rb_xor(rb_build(array(1L, 2L)), rb_build(array(2L, 3L))));Returned result:
+------------+ | _c0 | +------------+ | [1,3] | +------------+
RB_ANDNOT
Syntax
roaringbitmap rb_andnot(roaringbitmap a, roaringbitmap b)Description
Calculates the complement of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The complement of two roaring bitmaps is returned. The type of the return value is RoaringBitmap. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_andnot_null2emptyfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_to_array(rb_andnot(rb_build(array(1, 2)), rb_build(array(2, 3))));Returned result:
+------------+ | _c0 | +------------+ | [1] | +------------+Example 2
-- [1] is returned. SELECT rb_to_array(rb_andnot(rb_build(array(1L, 2L)), rb_build(array(2L, 3L))));Returned result:
+------------+ | _c0 | +------------+ | [1] | +------------+
RB_AND_CARDINALITY
Syntax
bigint rb_and_cardinality(roaringbitmap a, roaringbitmap b)Description
Calculates the cardinality of the intersection of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The cardinality of the intersection of two roaring bitmaps is returned. The type of the return value is BIGINT. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_and_null2empty_cardinalityfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_and_cardinality(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+Example 2
-- 1 is returned. SELECT rb_and_cardinality(rb_build(array(1L, 2L)), rb_build(array(2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+
RB_OR_CARDINALITY
Syntax
bigint rb_or_cardinality(roaringbitmap a, roaringbitmap b)Description
Calculates the cardinality of the union of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The cardinality of the union of two roaring bitmaps is returned. The type of the return value is BIGINT. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_or_null2empty_cardinalityfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_or_cardinality(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------------+ | _c0 | +------------+ | 3 | +------------+Example 2
SELECT rb_or_cardinality(rb_build(array(1L, 2L)), rb_build(array(2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | 3 | +------------+
RB_XOR_CARDINALITY
Syntax
bigint rb_xor_cardinality(roaringbitmap a, roaringbitmap b)Description
Calculates the cardinality of the result of the XOR operation on two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The cardinality of the result of the XOR operation on two roaring bitmaps is returned. The type of the return value is BIGINT. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_xor_null2empty_cardinalityfunction converts the parameter that is NULL into an empty set.Examples
Example 1
SELECT rb_xor_cardinality(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+Example 2
-- 2 is returned. SELECT rb_xor_cardinality(rb_build(array(1L, 2L)), rb_build(array(2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+
RB_ANDNOT_CARDINALITY
Syntax
bigint rb_andnot_cardinality(roaringbitmap a, roaringbitmap b)Description
Calculates the cardinality of the complement of two roaring bitmaps.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
The cardinality of the complement of two roaring bitmaps is returned. The type of the return value is BIGINT. If one of the parameters is NULL, NULL is returned.
NoteIf one of the parameters is NULL, the
rb_andnot_null2empty_cardinalityfunction converts the parameter that is NULL into an empty set.Examples
Example 1
-- 1 is returned. SELECT rb_andnot_cardinality(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+Example 2
SELECT rb_andnot_cardinality(rb_build(array(1L, 2L)), rb_build(array(2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | 1 | +------------+
RB_EQUAL
Syntax
bool rb_equal(roaringbitmap a, roaringbitmap b)Description
Determines whether two roaring bitmaps are equal.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
A value of the BOOLEAN type is returned.
Examples
Example 1
SELECT rb_equal(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------+ | _c0 | +------+ | false | +------+Example 2
SELECT rb_equal(rb_build(array(1, 2)), rb_build(array(2, 1)));Returned result:
+------+ | _c0 | +------+ | true | +------+
RB_NOT_EQUAL
Syntax
bool rb_not_equal(roaringbitmap a, roaringbitmap b)Description
Determines whether two roaring bitmaps are not equal.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
A value of the BOOLEAN type is returned.
Examples
Example 1
SELECT rb_not_equal(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------+ | _c0 | +------+ | true | +------+Example 2
SELECT rb_not_equal(rb_build(array(1, 2)), rb_build(array(2, 1)));Returned result:
+------+ | _c0 | +------+ | false | +------+
RB_CONTAINS
Syntax
bool rb_contains(roaringbitmap a, roaringbitmap b)Description
Determines whether the first roaring bitmap contains the second roaring bitmap.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
A value of the BOOLEAN type is returned.
Examples
Example 1
SELECT rb_contains(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------+ | _c0 | +------+ | false | +------+Example 2
SELECT rb_contains(rb_build(array(1, 2, 3)), rb_build(array(1, 2)));Returned result:
+------+ | _c0 | +------+ | true | +------+
RB_INTERSECT
Syntax
bool rb_intersect(roaringbitmap a, roaringbitmap b)Description
Determines whether two roaring bitmaps intersect.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
A value of the BOOLEAN type is returned.
Examples
Example 1
SELECT rb_intersect(rb_build(array(1, 2)), rb_build(array(2, 3)));Returned result:
+------+ | _c0 | +------+ | true | +------+Example 2
SELECT rb_intersect(rb_build(array(1, 2)), rb_build(array(3, 4)));Returned result:
+------+ | _c0 | +------+ | false | +------+
RB_IS_EMPTY
Syntax
bool rb_is_empty(roaringbitmap a)Description
Determines whether a roaring bitmap is empty.
Parameters
a: required. The data is of the RoaringBitmap type.
b: required. The data is of the RoaringBitmap type.
Return value
A value of the BOOLEAN type is returned.
Examples
Example 1
SELECT rb_is_empty(rb_build(array(0, 1, 2)));Returned result:
+------+ | _c0 | +------+ | false | +------+Example 2
SELECT rb_is_empty(rb_and(rb_build(array(0, 1, 2)), rb_build(array(3, 4, 5))));Returned result:
+------+ | _c0 | +------+ | true | +------+
RB_MAXIMUM
Syntax
int|bigint rb_maximum(roaringbitmap a)Description
Obtains the maximum value in a roaring bitmap.
Parameters
a: required. The data is of the RoaringBitmap type.
Return value
A value of the INT or BIGINT type is returned.
Examples
SELECT rb_maximum(rb_build(array(-1, 0, 1, 2)));Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+
RB_MINIMUM
Syntax
int|bigint rb_minimum(roaringbitmap a)Description
Obtains the minimum value in a roaring bitmap.
Parameters
a: required. The data is of the RoaringBitmap type.
Return value
A value of the INT or BIGINT type is returned.
Examples
SELECT rb_minimum(rb_build(array(-1, 0, 1, 2)));Returned result:
+------------+ | _c0 | +------------+ | -1 | +------------+
RB_RANGE
Syntax
roaringbitmap rb_range(roaringbitmap a, bigint start, bigint end)Description
Obtains a new collection of roaring bitmaps in the
[start, end)range.Parameters
a: required. The data is of the RoaringBitmap type.
start: required. The data is of the BIGINT type.
end: required. The data is of the BIGINT type.
Return value
A value of the RoaringBitmap type is returned.
Examples
Example 1
SELECT rb_to_array(rb_range(rb_build(array(-1, 0, 1, 2)), 0L, 2L));Returned result:
+------------+ | _c0 | +------------+ | [0,1] | +------------+Example 2
SELECT rb_to_array(rb_range(rb_build(array(-1, 0, 1, 2)), 3L, 5L));Returned result:
+------------+ | _c0 | +------------+ | [] | +------------+
RB_RANGE_CARDINALITY
Syntax
bigint rb_range_cardinality(roaringbitmap a, bigint start, bigint end)Description
Obtains the cardinality of the new collection of roaring bitmaps in the
[start, end)range.Parameters
a: required. The data is of the RoaringBitmap type.
start: required. The data is of the BIGINT type.
end: required. The data is of the BIGINT type.
Return value
A value of the BIGINT type is returned.
Examples
Example 1
SELECT rb_range_cardinality(rb_build(array(-1, 0, 1, 2)), 0L, 2L);Returned result:
+------------+ | _c0 | +------------+ | 2 | +------------+Example 2
SELECT rb_range_cardinality(rb_build(array(-1, 0, 1, 2)), 3L, 5L);Returned result:
+------------+ | _c0 | +------------+ | 0 | +------------+
RB_FILL
Syntax
roaringbitmap rb_fill(roaringbitmap a, bigint start, bigint end)Description
Obtains a new collection of roaring bitmaps after integers in the
[start, end)range are inserted into roaring bitmaps.Parameters
a: required. The data is of the RoaringBitmap type.
start: required. The data is of the BIGINT type.
end: required. The data is of the BIGINT type.
Return value
A value of the RoaringBitmap type is returned.
Examples
Example 1
SELECT rb_to_array(rb_fill(rb_build(array(-1, 0, 1, 2)), 0L, 2L));Returned result:
+------------+ | _c0 | +------------+ | [-1,0,1,2] | +------------+Example 2
SELECT rb_to_array(rb_fill(rb_build(array(-1, 0, 1, 2)), 3L, 5L));Returned result:
+------------+ | _c0 | +------------+ | [-1,0,1,2,3,4] | +------------+
RB_CLEAR
Syntax
roaringbitmap rb_clear(roaringbitmap a, bigint start, bigint end)Description
Obtains a new collection of roaring bitmaps after integers in the
[start, end)range are deleted from roaring bitmaps.Parameters
a: required. The data is of the RoaringBitmap type.
start: required. The data is of the BIGINT type.
end: required. The data is of the BIGINT type.
Return value
A value of the RoaringBitmap type is returned.
Examples
Example 1
SELECT rb_to_array(rb_clear(rb_build(array(-1, 0, 1, 2)), 0L, 2L));Returned result:
+------------+ | _c0 | +------------+ | [-1,2] | +------------+Example 2
SELECT rb_to_array(rb_clear(rb_build(array(-1, 0, 1, 2)), 3L, 5L));Returned result:
+------------+ | _c0 | +------------+ | [-1,0,1,2] | +------------+
RB_SERIALIZE
Syntax
bianry rb_serialize(roaringbitmap a)Description
Serializes values of the RoaringBitmap type into the BINARY type.
Parameters
a: required. The data is of the RoaringBitmap type.
Return value
A value of the BINARY type after serialization of roaring bitmap data is returned.
Examples
SELECT rb_serialize(rb_build(array(1L, 2L, 3L)));Returned result:
+------------+ | _c0 | +------------+ | =01=00=00=00=00=00=00=00=00=00=00=00:0=00=00=01=00=00=00=00=00=02=00=10=00=00=00=01=00=02=00=03=00 | +------------+
RB_DESERIALIZE
Syntax
roaringbitmap64 rb_deserialize(bianry a)Description
Deserializes values of the BINARY type into the RoaringBitmap64 type.
Parameters
a: required. The data is of the BINARY type.
Return value
A value of the RoaringBitmap64 type after deserialization of binary data is returned.
Examples
SELECT rb_to_array(rb_deserialize(rb_serialize(rb_build(array(1L, 2L, 3L)))));Returned result:
+------------+ | _c0 | +------------+ | [1,2,3] | +------------+
RB_DESERIALIZE_32
Syntax
roaringbitmap32 rb_deserialize(bianry a)Description
Deserializes values of the BINARY type into the RoaringBitmap32 type.
Parameters
a: required. The data is of the BINARY type.
Return value
A value of the RoaringBitmap32 type after deserialization of binary data is returned.
Examples
SELECT rb_to_array(rb_deserialize_32(rb_serialize(rb_build(array(1, 2, 3)))));Returned result:
+------------+ | _c0 | +------------+ | [1,2,3] | +------------+