Array constructors are used to create new array data types. OceanBase AI Database currently supports the array() and rb_build() constructors, and the [] operator.
array
The array() function is used to construct an array of data. The syntax is as follows:
array(elem1, elem2, elem3, ..., elemN)
[elem1, elem2, elem3, ..., elemN]
elem1~elmenN: The input parameters must be of the same data type. For information about the supported array data types, see Overview of Array Element Types.
An example is as follows:
SELECT array(1, 2, 3);
+----------------+
| array(1, 2, 3) |
+----------------+
| [1,2,3] |
+----------------+
1 row in set
rb_build
The rb_build() function is used to convert an array of basic integer data into highly compressed bitmap data (RoaringBitmap). The syntax is as follows:
rb_build(arr)
The input parameters are described as follows:
- The type of
arrmust be an array.
The return value is a RoaringBitmap containing all elements of the array.
The constraints are as follows:
- An array cannot contain empty elements.
- If the array is a nested array, recursively extract the base elements of each subarray and insert them into the Roaringbitmap.
- RoaringBitmap supports inserting unsigned 64-bit integers (uint64) and signed 32-bit integers (int32) data. This is consistent with the behavior of Bitmap Constructor. Signed 32-bit integer inputs that are negative will first be converted to unsigned 32-bit integers before being inserted into the RoaringBitmap. Therefore, the allowed input integer range is from the minimum value of a signed 32-bit integer to the maximum value of an unsigned 64-bit integer, that is,
[INT32_MIN, UINT64_MAX].
An example is as follows:
SELECT rb_to_string(rb_build([1.2]));
ERROR 5083 (22000): Invalid data type for the operation
SELECT rb_to_string(rb_build([0,1,2]));
+---------------------------------+
| rb_to_string(rb_build([0,1,2])) |
+---------------------------------+
| 0,1,2 |
+---------------------------------+
1 row in set
SELECT rb_to_string(rb_build([[0,1],[2],[2,3]]));
+-------------------------------------------+
| rb_to_string(rb_build([[0,1],[2],[2,3]])) |
+-------------------------------------------+
| 0,1,2,3 |
+-------------------------------------------+
1 row in set
[]
The operator [] can also be used to construct array data, as shown in the following example:
SELECT [1, 2, 3];
+-----------+
| [1, 2, 3] |
+-----------+
| [1,2,3] |
+-----------+
1 row in set