GROUP_BITMAP_STATE

Function Description

The GROUP_BITMAP_STATE function is used to construct a bitmap type result based on the input expression (expr). This function is typically used for grouping operations on integer type data and converting the unique values of each group into a bitmap array.

Parameter Description

  • expr: The integer type expression to be processed.

Return Type

  • Returns a bitmap type result.

Example

Below is an example of using the GROUP_BITMAP_STATE function. We have a data table with two columns, c and v. We want to group by the values in column c and convert the unique values in column v of each group into a bitmap array.

SELECT c, bitmap_to_array(group_bitmap_state(v)) AS bitmap_array
FROM VALUES ('a', 1), ('a', 2), ('a', 2), ('b', 3) AS v(c, v)
GROUP BY c;

After executing the above query, we will get the following result:

 c  | bitmap_array
---+-------------
 a  | [1,2]
 b  | [3]

In this example, we can see that group a contains two unique values 1 and 2, so the returned bitmap array is [1,2]. Group b only contains one unique value 3, so the returned bitmap array is [3].